14539: Fixes and simplifies the escape() function. Updates test.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 16 Jan 2019 22:34:34 +0000 (19:34 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 16 Jan 2019 22:34:34 +0000 (19:34 -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 a119da2387a2620e886ce6325aebab76c5fcddbf..9b29e8804607f17dfff2adca35d0a44b99f2b6d6 100644 (file)
@@ -12,7 +12,8 @@ def escape(path):
     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)
+    path = re.sub(
+        '([:\000-\040])', lambda m: "\\%03o" % ord(m.group(1)), path)
     return path
 
 def normalize_stream(stream_name, stream):
index 91d1797d052e6cbbe0d2491bbc5d41cbea93bc4d..66f062c167250b2873ea6a047554b5986f17ee46 100644 (file)
@@ -960,6 +960,7 @@ class NewCollectionTestCase(unittest.TestCase, CollectionTestMixin):
 
     def test_other_special_chars_on_file_token(self):
         cases = [
+            ('\\000', '\0'),
             ('\\011', '\t'),
             ('\\012', '\n'),
             ('\\072', ':'),