Fix issue for PY3 where file content has not BOM and isn't ascii by decodeing to...
authorWilliam Deegan <bill@baddogconsulting.com>
Wed, 23 Aug 2017 17:35:15 +0000 (10:35 -0700)
committerWilliam Deegan <bill@baddogconsulting.com>
Wed, 23 Aug 2017 17:35:15 +0000 (10:35 -0700)
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py

index 8c1161d08a9528b8bc9e9232a9fbce41bcd030e5..638819a74bffd4de20d85a364028529f162d1751 100644 (file)
@@ -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):
index 399ac06adce9f4ec22b6e3624699f5cabeb67b96..c211ee1f5dad21d6b9686044b52166ac08f04f41 100644 (file)
@@ -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)