Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def from_file(cls, filename, arcname=None, *, strict_timestamps=True):

def is_dir(self):
"""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
Expand Down Expand Up @@ -1731,6 +1731,9 @@ def _extract_member(self, member, targetpath, pwd):
# filter illegal characters on Windows
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.normpath(targetpath)

Expand Down Expand Up @@ -1820,7 +1823,7 @@ def writestr(self, zinfo_or_arcname, data,
date_time=time.localtime(time.time())[:6])
zinfo.compress_type = self.compression
zinfo._compresslevel = self.compresslevel
if zinfo.filename[-1] == '/':
if zinfo.filename.endswith('/'):
zinfo.external_attr = 0o40775 << 16 # drwxrwxr-x
zinfo.external_attr |= 0x10 # MS-DOS directory flag
else:
Expand Down