mirror of
https://github.com/python/cpython.git
synced 2025-09-10 10:47:34 +00:00
gh-98286: handle empty filename in ZipFile/ZipInfo properly (#98346)
effectively code modernization and a meaningful exception.
This commit is contained in:
parent
0023f51deb
commit
7ea10567af
1 changed files with 5 additions and 2 deletions
|
@ -553,7 +553,7 @@ class ZipInfo (object):
|
||||||
|
|
||||||
def is_dir(self):
|
def is_dir(self):
|
||||||
"""Return True if this archive member is a directory."""
|
"""Return True if this archive member is a directory."""
|
||||||
return self.filename[-1] == '/'
|
return self.filename.endswith('/')
|
||||||
|
|
||||||
|
|
||||||
# ZIP encryption uses the CRC32 one-byte primitive for scrambling some
|
# ZIP encryption uses the CRC32 one-byte primitive for scrambling some
|
||||||
|
@ -1731,6 +1731,9 @@ class ZipFile:
|
||||||
# filter illegal characters on Windows
|
# filter illegal characters on Windows
|
||||||
arcname = self._sanitize_windows_name(arcname, os.path.sep)
|
arcname = self._sanitize_windows_name(arcname, os.path.sep)
|
||||||
|
|
||||||
|
if not arcname:
|
||||||
|
raise ValueError("Empty filename.")
|
||||||
|
|
||||||
targetpath = os.path.join(targetpath, arcname)
|
targetpath = os.path.join(targetpath, arcname)
|
||||||
targetpath = os.path.normpath(targetpath)
|
targetpath = os.path.normpath(targetpath)
|
||||||
|
|
||||||
|
@ -1820,7 +1823,7 @@ class ZipFile:
|
||||||
date_time=time.localtime(time.time())[:6])
|
date_time=time.localtime(time.time())[:6])
|
||||||
zinfo.compress_type = self.compression
|
zinfo.compress_type = self.compression
|
||||||
zinfo._compresslevel = self.compresslevel
|
zinfo._compresslevel = self.compresslevel
|
||||||
if zinfo.filename[-1] == '/':
|
if zinfo.filename.endswith('/'):
|
||||||
zinfo.external_attr = 0o40775 << 16 # drwxrwxr-x
|
zinfo.external_attr = 0o40775 << 16 # drwxrwxr-x
|
||||||
zinfo.external_attr |= 0x10 # MS-DOS directory flag
|
zinfo.external_attr |= 0x10 # MS-DOS directory flag
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue