diff --git a/Lib/zipfile.py b/Lib/zipfile.py index fe012968b37..aa88563e5f1 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -940,7 +940,9 @@ def _extract_member(self, member, targetpath, pwd): """ # build the destination pathname, replacing # forward slashes to platform specific separators. - if targetpath[-1:] in (os.path.sep, os.path.altsep): + # Strip trailing path separator, unless it represents the root. + if (targetpath[-1:] in (os.path.sep, os.path.altsep) + and len(os.path.splitdrive(targetpath)[1]) > 1): targetpath = targetpath[:-1] # don't include leading "/" from file name if present diff --git a/Misc/NEWS b/Misc/NEWS index 03d318d9299..62f2948f872 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -36,6 +36,9 @@ Core and Builtins Library ------- +- Issue #5692: In :class:`zipfile.Zipfile`, fix wrong path calculation when + extracting a file to the root directory. + - Issue #2245: aifc now skips chunk types it doesn't recognize, per spec. - Issue #4305: ctypes should now build again on mipsel-linux-gnu