From 3d23564348799dfee88466f7439662c9d1e1b698 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Tue, 28 Mar 2017 13:57:25 +0100 Subject: [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 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 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 --- sos/reporting.py | 6 ++++++ 1 file changed, 6 insertions(+) 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: -- cgit