summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2017-08-24 10:13:35 -0700
committerWilliam Deegan <bill@baddogconsulting.com>2017-08-24 10:13:35 -0700
commit84f14518cefda575fde05dcd06e68b487c3c11d2 (patch)
treed334bd22bfc4c4cd30252929558cd93141407475
parentaff283ac751aeecdb6cd7d5ee0153ad874e550a5 (diff)
downloadscons-84f14518cefda575fde05dcd06e68b487c3c11d2.tar.gz
Updates to get_text_content() logic and tests
-rw-r--r--src/engine/SCons/Node/FS.py9
-rw-r--r--src/engine/SCons/Node/FSTests.py4
2 files changed, 8 insertions, 5 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 606ecfda..c31ac6c4 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -2654,9 +2654,12 @@ class File(Base):
if contents[:len(codecs.BOM_UTF16_BE)] == codecs.BOM_UTF16_BE:
return contents[len(codecs.BOM_UTF16_BE):].decode('utf-16-be')
try:
- return contents.decode('utf-8',errors='backslashreplace')
- except (UnicodeDecodeError, AttributeError) as e:
- return contents
+ return contents.decode('utf-8')
+ except UnicodeDecodeError as e:
+ try:
+ return contents.decode('latin-1')
+ except UnicodeDecodeError as e:
+ return contents.decode('utf-8', error='backslashreplace')
def get_content_hash(self):
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index c211ee1f..273f8097 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -1317,10 +1317,10 @@ class FSTestCase(_tempdirTestCase):
# Check for string which doesn't have BOM and isn't valid
# ASCII
- test_string = b'Gan\xef\xbf\xbdauge'
+ test_string = b'Gan\xdfauge'
test.write('latin1_file', test_string)
f1 = fs.File(test.workpath("latin1_file"))
- assert f1.get_text_contents() == test_string.decode('utf-8'), \
+ assert f1.get_text_contents() == test_string.decode('latin-1'), \
f1.get_text_contents()
def nonexistent(method, s):