summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-06 22:38:17 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-06 22:38:17 -0500
commit76e924a2b4268d9821c7fd6c69b6a092ddc936b1 (patch)
treeee84892f0e3b8d4aa9291dedc21dd643e1d75a53
parent8db9fdf865ca0719cf2a37af25b93f53f39eb74c (diff)
downloadpython-coveragepy-76e924a2b4268d9821c7fd6c69b6a092ddc936b1.tar.gz
Prevent UnicodeErrors in HTML reports with Unicode configuration values
-rw-r--r--CHANGES.rst3
-rw-r--r--coverage/misc.py6
-rw-r--r--tests/test_misc.py7
3 files changed, 13 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 91218bb..d56aebe 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -53,6 +53,9 @@ Unreleased
- Deal properly with non-ASCII file names in an ASCII-only world, `issue 533`_.
+- Plugins that set Unicode configuration values could cause UnicodeErrors when
+ generating HTML reports. This is now fixed.
+
- Prevented deprecation warnings from configparser that happened in some
circumstances, closing `issue 530`_.
diff --git a/coverage/misc.py b/coverage/misc.py
index 9b1894f..5d330c6 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -12,7 +12,7 @@ import sys
import types
from coverage import env
-from coverage.backward import string_class, to_bytes, unicode_class
+from coverage.backward import to_bytes, unicode_class
ISOLATED_MODULES = {}
@@ -179,8 +179,8 @@ class Hasher(object):
def update(self, v):
"""Add `v` to the hash, recursively if needed."""
self.md5.update(to_bytes(str(type(v))))
- if isinstance(v, string_class):
- self.md5.update(to_bytes(v))
+ if isinstance(v, unicode_class):
+ self.md5.update(v.encode('utf8'))
elif isinstance(v, bytes):
self.md5.update(v)
elif v is None:
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 38be345..96b5100 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -34,6 +34,13 @@ class HasherTest(CoverageTest):
h2.update(b"Goodbye!")
self.assertNotEqual(h1.hexdigest(), h2.hexdigest())
+ def test_unicode_hashing(self):
+ h1 = Hasher()
+ h1.update(u"Hello, world! \N{SNOWMAN}")
+ h2 = Hasher()
+ h2.update(u"Goodbye!")
+ self.assertNotEqual(h1.hexdigest(), h2.hexdigest())
+
def test_dict_hashing(self):
h1 = Hasher()
h1.update({'a': 17, 'b': 23})