14539: Fixes literal backslash escaping.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 16 Jan 2019 21:33:49 +0000 (18:33 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 16 Jan 2019 21:33:49 +0000 (18:33 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

sdk/python/arvados/_normalize_stream.py
sdk/python/tests/test_collections.py

index f1f6052cddb9aebff6e4c47652795b4a63f1995c..a119da2387a2620e886ce6325aebab76c5fcddbf 100644 (file)
@@ -8,14 +8,11 @@ from . import config
 import re
 
 def escape(path):
-    replacements = [
-        ('\t', '\\011'),
-        ('\n', '\\012'),
-        (' ', '\\040'),
-    ]
-    path = re.sub('\\\\([0-3][0-7][0-7])', lambda m: '\\134'+m.group(1), path)
-    for a, b in replacements:
-        path = path.replace(a, b)
+    # Escape literal backslash
+    path = re.sub('\\\\', lambda m: '\\134', path)
+    # Escape other special chars. Py3's oct() output differs from Py2, this takes
+    # care of those differences.
+    path = re.sub('([\t\n\r: ])', lambda m: '\\'+oct(ord(m.group(1))).replace('o', '')[-3:], path)
     return path
 
 def normalize_stream(stream_name, stream):
index f3ad16ecfe4aaeced2f969c6cc6453a33c8daaa2..91d1797d052e6cbbe0d2491bbc5d41cbea93bc4d 100644 (file)
@@ -962,6 +962,8 @@ class NewCollectionTestCase(unittest.TestCase, CollectionTestMixin):
         cases = [
             ('\\011', '\t'),
             ('\\012', '\n'),
+            ('\\072', ':'),
+            ('\\134400', '\\400'),
         ]
         for encoded, decoded in cases:
             manifest = '. d41d8cd98f00b204e9800998ecf8427e+0 0:0:some%sfile.txt\n' % encoded