Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
The zipfile module currently doesn't replaceos.altsep with/ in filename in cases whereos.altsep is notNone and not"/".
I'm not currently aware of any cases whereos.altsep is notNone or"/", so I don't think this is currently causing any issues, but it's at least not consistent withthe documentation which states thatos.altsep is "An alternative character used by the operating system to separate pathname components".
To reproduce the issue, the code below manually setsos.sep andos.altsep to be the normal Windows values, then swaps them. This should have no effect on the resulting zip file since the values should both be treated as valid path separators.
importioimportntpathimportosimportzipfiledefshow_zip():zf=zipfile.ZipFile(io.BytesIO(),'w')zf.writestr("a/b/","")zf.writestr("a/b\\","")zf.writestr("a\\b/","")zf.writestr("a\\b\\","")print([x.filenameforxinzf.infolist()])os.sep=ntpath.sepos.altsep=ntpath.altsepshow_zip()os.altsep,os.sep=os.sep,os.altsepshow_zip()
Expected output:
['a/b/', 'a/b/', 'a/b/', 'a/b/']['a/b/', 'a/b/', 'a/b/', 'a/b/']Actual output:
['a/b/', 'a/b/', 'a/b/', 'a/b/']['a/b/', 'a/b\\', 'a\\b/', 'a\\b\\']Environment:Python 3.11.0a7+ (heads/main:56f9844014, May 2 2022, 15:22:18) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status