diff options
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | coverage/misc.py | 6 | ||||
-rw-r--r-- | tests/test_misc.py | 7 |
3 files changed, 13 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 91218bba..d56aebef 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 9b1894f3..5d330c6d 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 38be3456..96b5100b 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}) |