diff options
author | Georg Brandl <georg@python.org> | 2013-09-16 10:45:43 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2013-09-16 10:45:43 +0200 |
commit | 4cd0ec789ad35dc4c1f7c3b4c91053e9c8e00a89 (patch) | |
tree | 205cdd5c0e343085a974af0993c653e275e6489a | |
parent | 3e04abf47be999abcdea773893e4b7db1a71e9ce (diff) | |
download | sphinx-4cd0ec789ad35dc4c1f7c3b4c91053e9c8e00a89.tar.gz |
Closes #1185: Don't crash when a Python module has a wrong or no encoding declared,
and non-ASCII characters are included.
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | sphinx/util/__init__.py | 14 |
2 files changed, 9 insertions, 7 deletions
@@ -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 8bedda12..229c3ad6 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 |