Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Zipfile module doesn't replaceos.altsep in filenames in some cases #92184

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@pR0Ps

Description

@pR0Ps

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

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp