GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Zipfile module doesn't replace `os.altsep` in filenames in some cases · Issue #92184 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
#92185
Closed
Zipfile module doesn't replace os.altsep in filenames in some cases#92184
#92185
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@pR0Ps
pR0Ps
opened on May 2, 2022
Issue body actions

The zipfile module currently doesn't replace os.altsep with / in filename in cases where os.altsep is not None and not "/".

I'm not currently aware of any cases where os.altsep is not None or "/", so I don't think this is currently causing any issues, but it's at least not consistent with the documentation which states that os.altsep is "An alternative character used by the operating system to separate pathname components".

To reproduce the issue, the code below manually sets os.sep and os.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.

import io
import ntpath
import os
import zipfile

def show_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.filename for x in zf.infolist()])

os.sep = ntpath.sep
os.altsep = ntpath.altsep
show_zip()

os.altsep, os.sep = os.sep, os.altsep
show_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

  • GH-92184: Convert os.altsep to '/' in filenames when creating ZipInfo objects #92185

Activity

  1. pR0Ps
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 2, 2022
  2. erlend-aasland
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on May 2, 2022
  3. serhiy-storchaka
    added this to @serhiy-storchaka's project python-zipfileon May 8, 2022
  4. serhiy-storchaka
    added this to Zipfile issues 📦on May 19, 2022
  5. gpshead commented on May 11, 2023

    @gpshead
    gpshead
    on May 11, 2023
    Member
    More actions

    i'm not convinced this was really worthwhile... given there are no known applicable platforms, but the logic in the PR was trivial enough and is pedantically correct for consistency. It is set to automerge. Thanks!

  6. gpshead
    closed this as completedin #92185on May 11, 2023
  7. github-project-automation
    moved this to Done in Zipfile issues 📦on May 11, 2023
  8. github-project-automation
    moved this to Done in @serhiy-storchaka's project python-zipfileon May 11, 2023
  9. gpshead
    added a commit that references this issue on May 11, 2023

    GH-92184: Convert os.altsep to '/' in filenames when creating ZipInfo…

    4abfe6a
  10. carljm
    added 2 commits that reference this issue on May 11, 2023

    Merge branch 'main' into supermon

    19b3d9e

    Merge branch 'main' into fixloadsuperspec

    4456dd6
  11. pR0Ps commented on May 11, 2023

    @pR0Ps
    pR0Ps
    on May 11, 2023
    ContributorAuthor
    More actions

    I'm not convinced this was really worthwhile

    Yeah, I'm with you there. It was more just something I noticed while fixing something else and figured I'd make a quick drive-by commit to fix. Thanks for merging it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    • Zipfile issues 📦
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.