aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2017-03-28 13:57:25 +0100
committerBryn M. Reeves <bmr@redhat.com>2017-03-28 13:57:25 +0100
commit3d23564348799dfee88466f7439662c9d1e1b698 (patch)
treeb87578ca78a5f4aac2922f48b770202916810166
parent670a6c86348a0b6fad095485de1f660e808117f9 (diff)
downloadsos-3d23564348799dfee88466f7439662c9d1e1b698.tar.gz
[reporting] workaround six mishandling of '\$' strings
There is a problem with six's handling of strings that end with a backslash: https://bitbucket.org/gutworth/six/issues/60/sixu-mishandles-string-ending-in-backslash This leads to an ugly exception during reporting if any filename ends with this character: Traceback (most recent call last): File "/usr/sbin/sosreport", line 25, in <module> main(sys.argv[1:]) File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1632, in main sos.execute() File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1607, in execute self.plain_report() File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1358, in plain_report output = PlainTextReport(report).unicode() File "/usr/lib/python2.7/site-packages/sos/reporting.py", line 151, in unicode else six.u(i)), buf)) File "/usr/lib/python2.7/site-packages/sos/reporting.py", line 151, in <lambda> else six.u(i)), buf)) File "/usr/lib/python2.7/site-packages/six.py", line 647, in u return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 25: \ at end of string Avoid this problem by re-packing the buffer and adding a single ' ' character to the end of any string ending with '\'. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/reporting.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/sos/reporting.py b/sos/reporting.py
index 679284ea..0bb7d29e 100644
--- a/sos/reporting.py
+++ b/sos/reporting.py
@@ -147,6 +147,12 @@ class PlainTextReport(object):
for type_, format_, header in self.subsections:
self.process_subsection(section_contents, type_.ADDS_TO,
header, format_)
+
+ # Workaround python.six mishandling of strings ending in '/' by
+ # adding a single space following any '\' at end-of-line.
+ # See Six issue #60.
+ buf = [(val + " ") if val.endswith('\\') else val for val in buf]
+
output = u'\n'.join(map(lambda i: (i if isinstance(i, six.text_type)
else six.u(i)), buf))
if six.PY3: