summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-09-16 10:45:43 +0200
committerGeorg Brandl <georg@python.org>2013-09-16 10:45:43 +0200
commit4cd0ec789ad35dc4c1f7c3b4c91053e9c8e00a89 (patch)
tree205cdd5c0e343085a974af0993c653e275e6489a
parent3e04abf47be999abcdea773893e4b7db1a71e9ce (diff)
downloadsphinx-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--CHANGES2
-rw-r--r--sphinx/util/__init__.py14
2 files changed, 9 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index 5a12230c..184febd6 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 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