diff --git a/CHANGES b/CHANGES index 5a12230ce..184febd6d 100644 --- a/CHANGES +++ b/CHANGES @@ -45,6 +45,8 @@ Bugs fixed * #1162, PR#139: singlehtml builder didn't copy images to _images/. * #1173: Adjust setup.py dependencies because Jinja2 2.7 discontinued compatibility with Python < 3.3 and Python < 2.6. Thanks to Alexander Dupuy. +* #1185: Don't crash when a Python module has a wrong or no encoding declared, + and non-ASCII characters are included. * #1188: sphinx-quickstart raises UnicodeEncodeError if "Project version" includes non-ASCII characters. * #1189: "Title underline is too short" WARNING is given when using fullwidth diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 8bedda126..229c3ad6b 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -323,15 +323,15 @@ def parselinenos(spec, total): def force_decode(string, encoding): """Forcibly get a unicode string out of a bytestring.""" if isinstance(string, bytes): - if encoding: - string = string.decode(encoding) - else: - try: + try: + if encoding: + string = string.decode(encoding) + else: # try decoding with utf-8, should only work for real UTF-8 string = string.decode('utf-8') - except UnicodeError: - # last resort -- can't fail - string = string.decode('latin1') + except UnicodeError: + # last resort -- can't fail + string = string.decode('latin1') return string