mirror of
https://github.com/python/cpython.git
synced 2025-08-16 23:01:34 +00:00
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.
This commit is contained in:
parent
5b95eb90a7
commit
7d4d074c99
3 changed files with 11 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue