From 06509092b4874d87680fd714927c5a3061528e13 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Wed, 23 Aug 2017 10:35:15 -0700 Subject: Fix issue for PY3 where file content has not BOM and isn't ascii by decodeing to utf-8 --- src/engine/SCons/Node/FS.py | 2 +- src/engine/SCons/Node/FSTests.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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) -- cgit v0.12