fix(open): honour the requested type for every document container - #735
Open
andiwand wants to merge 1 commit into
Open
fix(open): honour the requested type for every document container#735andiwand wants to merge 1 commit into
andiwand wants to merge 1 commit into
Conversation
`open(file, as)` returned whatever an odf, ooxml or legacy MS container turned out to hold, whatever `as` said, while the flat-odf branch added alongside them checked. So `open(packaged_odt, opendocument_graphics)` answered with a text document and `open(flat_odt, opendocument_graphics)` threw - the public contract depended on which encoding of the same document the caller happened to hold. `open_file_as` documents itself as decoding "as exactly @p as", and the probing path already treats a throw as "not this type, try the next", so the check costs it nothing. An encrypted ooxml is the one reading that is not its own container's: it names no inner type until it is decrypted, so it still answers for the type that was asked for - which is what `html_output_test` expects of every encrypted docx and xlsx in the reference set. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015E5WrxdYxfoBE7JUotBtqh
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.
🤖 Generated with Claude Code
Stacked on #731 — review it after that one, and the base will retarget to
mainwhen #731 merges.Why
A local review of #731 flagged that its new flat-odf branch is the only one in
open_file_asthat checks what it decoded against what was asked for:Same document, two encodings, two answers. The looseness is older than #731 — it sits in the odf, ooxml and legacy-MS branches alike — but #731 is what makes it visible, so this fixes all three rather than relaxing the new one.
open_file_asalready documents itself as decoding "as exactlyas", and the probing path inopen_filetreats a throw as "not this type, try the next", so tightening costs it nothing and makes probing more accurate.What
file_type() == asbefore returning, mirroring what the flat branch does.is_the_requested_ooxmllets it answer for whichever type was asked for.html_output_testrelies on this for every encrypted docx and xlsx in the reference set — the first cut without it failed exactly those two.Tests
File.opening_as_the_wrong_document_type_throwscovers odt/docx/doc,File.a_flat_document_and_a_package_answer_a_wrong_type_alikepins the asymmetry itself, andFile.an_encrypted_ooxml_opens_as_the_type_asked_forpins the exception. All three wrong-type cases were verified to fail against the branch without the fix.Full suite: 1005 passed, 0 failed (reference output included).