Skip to content

Keep stateful encoding output within the filename byte limit - #80

Open
rupayon123 wants to merge 1 commit into
thombashi:masterfrom
rupayon123:fix/stateful-encoding-byte-limit
Open

rupayon123 wants to merge 1 commit into
thombashi:masterfrom
rupayon123:fix/stateful-encoding-byte-limit

Conversation

@rupayon123

Copy link
Copy Markdown

With fs_encoding="iso2022_jp", sanitizing 日本語 to an 8-byte limit currently returns 日本, which encodes to 10 bytes. validate_filename rejects that result, and validate_after_sanitize=True raises instead of producing the fitting prefix 日.

Decoding a byte prefix can discard a stateful codec's closing escape sequence. Trim the decoded suffix until its complete encoding fits the budget. The regression covers ISO-2022-JP, HZ and UTF-7, plus UTF-8/UTF-16 controls, through both sanitizer paths and the validator.

Validation on CPython 3.13/macOS: 4,176 tests pass with 17 existing skips; coverage is 94.3%. Pyright, codespell, formatting, package checks and the docs build pass. Ruff's 129 diagnostics are identical on the pristine base and this patch; the two docs warnings also match baseline. The other Python/OS combinations were not run locally. No dependency or lint configuration changes.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant