You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee=Noneclosed_at=<Date2021-08-04.20:02:09.723>created_at=<Date2021-01-29.20:28:48.419>labels= ['type-bug', 'library', '3.9', '3.10', '3.11']
title='Zipfile with leading slashes'updated_at=<Date2021-08-04.20:02:09.722>user='https://bugs.python.org/garrisontaylor'
The generated zipfile contains "/some_folder/some_file.txt". However, according to the specification for zip files, this is invalid. See below, from the .ZIP File Format Specification version 6.3.9:
126.96.36.199 The name of the file, with optional relative path.
The path stored MUST NOT contain a drive or
device letter, or a leading slash. All slashes
MUST be forward slashes '/' as opposed to
backwards slashes '\' for compatibility with Amiga
and UNIX file systems etc. If input came from standard
input, there is no file name field.
This is significant because the default Windows Explorer zip file extractor cannot handle zip files that contain a leading slash, producing an error that "The compressed (zipped) folder is invalid."
Raising an error is probably not warranted because zip files are often created on one system and used on another, so you can't raise an error based on current OS, and having a leading slash in the name is both useful and does work in MacOS and Unix. It probably works in some unzip programs on Windows as well (if anyone can test that would be great).
Therefore I propose adding the following notes to ZipInfo, ZipFile.write() and ZipFile.writestr():
Note: a leading slash in the archive / filename may lead to the archive being un-openable in some zip programs on Windows systems.