diff options
-rw-r--r-- | src/engine/SCons/Node/FS.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/Node/FSTests.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 8c1161d..638819a 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -2656,7 +2656,7 @@ class File(Base): try: return contents.decode() except (UnicodeDecodeError, AttributeError) as e: - return contents + return contents.decode('utf-8') def get_content_hash(self): diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 399ac06..c211ee1 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -1315,6 +1315,14 @@ class FSTestCase(_tempdirTestCase): assert eval('f1.get_text_contents() == u"Foo\x1aBar"'), \ f1.get_text_contents() + # Check for string which doesn't have BOM and isn't valid + # ASCII + test_string = b'Gan\xef\xbf\xbdauge' + test.write('latin1_file', test_string) + f1 = fs.File(test.workpath("latin1_file")) + assert f1.get_text_contents() == test_string.decode('utf-8'), \ + f1.get_text_contents() + def nonexistent(method, s): try: x = method(s, create = 0) |