Repository navigation
Fail only the file when EPUB or IMSCP XML names an unusable encoding - #874
Merged
Merged
Conversation
- Unknown encodings raise ET.ParseError instead of escaping as LookupError - Multi-byte encodings such as Shift_JIS are decoded with the declared Python codec and parsed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rtibblesbot
force-pushed
the
issue-855-ccd023
branch
from
October 18, 2026 20:53
2cbf3f9 to
3b68aea
Compare
rtibblesbot
marked this pull request as ready for review
October 18, 2026 20:54
rtibbles
approved these changes
Oct 19, 2026
rtibbles
left a comment
Member
There was a problem hiding this comment.
Code changes make sense, and the test coverage shows what this is fixing.
| ) | ||
|
|
||
| XML_ENCODING_DECLARATION_REGEX = re.compile( | ||
| rb"""^(?:\xef\xbb\xbf)?\s*<\?xml\s[^>]*?\bencoding\s*=\s*["']([A-Za-z][\w.:-]*)["']""" |
Member
There was a problem hiding this comment.
I was going to complain about using regex to read XML data - but this is a smart usage of it to discover the declared encoding when we are otherwise unable to parse the file with the default UTF encoding.
Contributor
Author
|
Quick check on rtibblesbot's work on this PR: react 👍 helpful · 😕 mixed · 👎 not helpful. Reply with anything specific. |
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
EPUB/IMSCP XML declaring an unknown (
bogus) or multi-byte (Shift_JIS) encoding raisedLookupError/ValueErrorand stopped the whole run.Shift_JIS,ISO-2022-JP) are decoded with the declared codec and re-parsed.References
Fixes #855. Same failure for SVGs: #813.
Reviewer guidance
Suggested review: Full code review.
parse_xml's decode-and-reparse (declared-encoding regex, expat error-code check) is the shared XML-parsing approach wanted, givenSVGValidationHandleruses an lxml fallback instead.bogus-labelled IMSCP manifest should fail the package even when its bytes are valid UTF-8, while a mislabelledShift_JISone is recovered.utf8orISO-2022-JP, which upstream rejects as not well-formed, should now process.AI usage
Used Claude Code to implement the fix and its tests from the issue's reproductions. Verified with the full test suite, prek, and a script that runs
process_file()on each acceptance-criteria fixture.🤖 Generated with Claude Code
Deviations from the issue spec
bogusmanifest:process_file()returnsNonewith a one-line.errorFilesubclass exists;ContentNode(uri=...).process_files()raises a one-lineInvalidNodeExceptioninstead. Adding a subclass is forbidden by AGENTS.md.Written by rtibblesbot, an LLM-based coding agent.
🔵 Post PR
Last updated: 2026-10-19 17:23 UTC