Title: Zipfile module doesn't replace `os.altsep` in filenames in some cases · Issue #92184 · python/cpython · GitHub
Open Graph Title: Zipfile module doesn't replace `os.altsep` in filenames in some cases · Issue #92184 · python/cpython
X Title: Zipfile module doesn't replace `os.altsep` in filenames in some cases · Issue #92184 · python/cpython
Description: 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 causi...
Open Graph Description: 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 "/", ...
X Description: 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...
Opengraph URL: https://github.com/python/cpython/issues/92184
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Zipfile module doesn't replace `os.altsep` in filenames in some cases","articleBody":"The zipfile module currently doesn't replace `os.altsep` with `/` in filename in cases where `os.altsep` is not `None` and not `\"/\"`.\r\n\r\nI'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](https://docs.python.org/3/library/os.html#os.altsep) which states that `os.altsep` is \"An alternative character used by the operating system to separate pathname components\".\r\n\r\nTo 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.\r\n\r\n```python\r\nimport io\r\nimport ntpath\r\nimport os\r\nimport zipfile\r\n\r\ndef show_zip():\r\n zf = zipfile.ZipFile(io.BytesIO(), 'w')\r\n zf.writestr(\"a/b/\", \"\")\r\n zf.writestr(\"a/b\\\\\", \"\")\r\n zf.writestr(\"a\\\\b/\", \"\")\r\n zf.writestr(\"a\\\\b\\\\\", \"\")\r\n print([x.filename for x in zf.infolist()])\r\n\r\nos.sep = ntpath.sep\r\nos.altsep = ntpath.altsep\r\nshow_zip()\r\n\r\nos.altsep, os.sep = os.sep, os.altsep\r\nshow_zip()\r\n```\r\n\r\nExpected output:\r\n```\r\n['a/b/', 'a/b/', 'a/b/', 'a/b/']\r\n['a/b/', 'a/b/', 'a/b/', 'a/b/']\r\n```\r\n\r\nActual output:\r\n```\r\n['a/b/', 'a/b/', 'a/b/', 'a/b/']\r\n['a/b/', 'a/b\\\\', 'a\\\\b/', 'a\\\\b\\\\']\r\n```\r\n\r\nEnvironment: `Python 3.11.0a7+ (heads/main:56f9844014, May 2 2022, 15:22:18) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin`\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-92185\r\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/pR0Ps","@type":"Person","name":"pR0Ps"},"datePublished":"2022-05-02T20:13:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/92184/cpython/issues/92184"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d55dbdff-53f6-dcaf-3fa2-b5099f7ebaf8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B214:2DA0A8:8F6F0C:C0B8C1:6969BE87 |
| html-safe-nonce | 5dcfad02f02d103c94b5237d3ef28b06585a2f4619cb0e2b16d77408891fa198 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjE0OjJEQTBBODo4RjZGMEM6QzBCOEMxOjY5NjlCRTg3IiwidmlzaXRvcl9pZCI6IjczMDA5MjQxNzI3NTk4NDI0MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1f749020e9e624189662248780c300fecf33de24db31b7f9c58150a9a205a47b |
| hovercard-subject-tag | issue:1223311561 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/92184/issue_layout |
| twitter:image | https://opengraph.githubassets.com/43ce49025ca808cb60b0347c00c59221a422e470f2dd2d97070011919f396875/python/cpython/issues/92184 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/43ce49025ca808cb60b0347c00c59221a422e470f2dd2d97070011919f396875/python/cpython/issues/92184 |
| og:image:alt | 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 "/", ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pR0Ps |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width