Bladeren bron

Support non-ascii characters in filenames in tar streams.

Jelmer Vernooij 2 jaren geleden
bovenliggende
commit
0f39ce5346
2 gewijzigde bestanden met toevoegingen van 2 en 3 verwijderingen
  1. 1 1
      dulwich/archive.py
  2. 1 2
      dulwich/tests/test_archive.py

+ 1 - 1
dulwich/archive.py

@@ -110,7 +110,7 @@ def tar_stream(store, tree, mtime, prefix=b"", format=""):
 
             info = tarfile.TarInfo()
             # tarfile only works with ascii.
-            info.name = entry_abspath.decode("ascii")
+            info.name = entry_abspath.decode('utf-8', 'surrogateescape')
             info.size = blob.raw_length()
             info.mode = entry.mode
             info.mtime = mtime

+ 1 - 2
dulwich/tests/test_archive.py

@@ -81,8 +81,7 @@ class ArchiveTests(TestCase):
         t1.add("ő".encode('utf-8'), 0o100644, b1.id)
         store.add_object(t1)
         stream = b"".join(tar_stream(store, t1, mtime=0))
-        BytesIO(stream)
-        tf = tarfile.TarFile(fileobj=stream)
+        tf = tarfile.TarFile(fileobj=BytesIO(stream))
         self.addCleanup(tf.close)
         self.assertEqual(["ő"], tf.getnames())