summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2017-08-23 10:35:15 -0700
committerWilliam Deegan <bill@baddogconsulting.com>2017-08-23 10:35:15 -0700
commit6fb2633243c7351ad53d2558e7388868c359e900 (patch)
tree526cdd49cfebe4be59a14af59a5bd6bd8be606f1
parent899928924663fe57d0e0baef6e40d5b02fa07754 (diff)
downloadscons-6fb2633243c7351ad53d2558e7388868c359e900.tar.gz
Fix issue for PY3 where file content has not BOM and isn't ascii by decodeing to utf-8
-rw-r--r--src/engine/SCons/Node/FS.py2
-rw-r--r--src/engine/SCons/Node/FSTests.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 8c1161d0..638819a7 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 399ac06a..c211ee1f 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)