Commit 7d4d074c authored by Lars Gustäbel's avatar Lars Gustäbel

Issue #13639: Accept unicode filenames in tarfile.open(mode="w|gz").

Passing a unicode filename to tarfile.open() along with mode "w|gz" failed
with a UnicodeError because the filename was not encoded properly before being
written to the gzipped stream in the FNAME extra field.
parent 5b95eb90
......@@ -454,6 +454,8 @@ class _Stream:
0)
timestamp = struct.pack("<L", long(time.time()))
self.__write("\037\213\010\010%s\002\377" % timestamp)
if type(self.name) is unicode:
self.name = self.name.encode("iso-8859-1", "replace")
if self.name.endswith(".gz"):
self.name = self.name[:-3]
self.__write(self.name + NUL)
......
......@@ -994,6 +994,13 @@ class StreamWriteTest(WriteTestBase):
finally:
os.umask(original_umask)
def test_issue13639(self):
try:
with tarfile.open(unicode(tmpname, sys.getfilesystemencoding()), self.mode):
pass
except UnicodeDecodeError:
self.fail("_Stream failed to write unicode filename")
class GNUWriteTest(unittest.TestCase):
# This testcase checks for correct creation of GNU Longname
......
......@@ -86,6 +86,8 @@ Core and Builtins
Library
-------
- Issue #13639: Accept unicode filenames in tarfile.open(mode="w|gz").
- Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
- Issue #7502: Fix equality comparison for DocTestCase instances. Patch by
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment