Repository navigation
gh-152845: Preserve ZIP encoding flags when appending - #161950
Merged
Merged
Conversation
|
Thanks @KasraGhodsi for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
GH-161960 is a backport of this pull request to the 3.15 branch. |
|
GH-161961 is a backport of this pull request to the 3.14 branch. |
ambv
pushed a commit
that referenced
this pull request
Nov 14, 2026
ambv
pushed a commit
that referenced
this pull request
Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Preserve the UTF-8/EFS flag when
zipfilerewrites existing entries in append mode, including ASCII filenames with UTF-8 entry comments. This keeps the central directory consistent with retained local headers and preserves the encoding indicated for comment bytes.Keep existing new-entry defaults: ordinary ASCII names remain CP437-tagged, explicit UTF-8 flags are honored, and new non-ASCII names remain UTF-8-tagged. Comments remain opaque bytes; the implementation does not infer UTF-8 merely because comment bytes are non-ASCII.
This is a narrowly scoped alternative to #152846 for the flag-preservation portion of #152845. For example,
b'\x82'is a valid CP437 comment but not valid UTF-8; changing its encoding flag without transcoding mislabels the data. The regression coverage also checks explicitly flagged ASCII entries with empty or ASCII comments. This PR does not addmetadata_encodingsupport to writing modes or additional encoding state toZipInfo.Testing
Tested on Linux aarch64 with a debug CPython 3.16.0a2+dev build, GCC 11.5.0, based on
727b56b4db5734864953a6586ea03633ef27bad5../python -m test -v test_zipfilecompleted successfully: 607 tests, three skips../python -m test -j4completed successfully: 51,364 tests reported run, 2,963 skipped.upstream/mainfor default-branch discovery; the standard invocation crashes in that Git lookup.git diff --checkpassed.Related work and scope
Issue: gh-152845
Related alternative implementation: #152846. This PR keeps the append bug fix separate from broader comment-encoding policy and
metadata_encodingenhancements; affected maintenance-branch backports can be considered separately.