fix(docx): an equation without its properties child drops every equation - #2445
Open
kevin (kevin9327) wants to merge 1 commit into
Open
fix(docx): an equation without its properties child drops every equation#2445kevin (kevin9327) wants to merge 1 commit into
kevin (kevin9327) wants to merge 1 commit into
Conversation
Every OMML element's properties child is optional -- <m:f> without <m:fPr> is a fraction with default properties -- but do_f, do_d, do_acc, do_bar and do_groupchr indexed it directly and raised KeyError. _pre_process_math runs over the whole of word/document.xml inside a blanket except Exception, so the crash discards the OMML rewrite for the entire part and every equation in the document is lost.
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.
Converting a .docx whose equations were written by something other than Word produces the document's prose with every equation missing — no error, no warning, just no math (issue #1512).
Every OMML element's properties child is optional.
<m:f>without<m:fPr>is a fraction with default properties, and the same goes for<m:d>,<m:acc>,<m:bar>and<m:groupChr>. Word always writes the child, because it carries the control run's formatting — intests/test_files/equations.docxevery<m:fPr>holds nothing but a<m:ctrlPr>— but nothing else has to.do_f,do_d,do_acc,do_baranddo_groupchrindexed the child directly (c_dict["fPr"]), so an equation that omits it raisesKeyError. The five already carry the spec's defaults; they just crash before reaching them.The damage is not local.
_pre_process_mathruns over all ofword/document.xmlinside a blanketexcept Exception, so one such equation discards the OMML rewrite for the whole part, and Mammoth cannot render raw OMML. Taking the existing fixture and dropping the element a non-Word producer would not have written:After the fix, 4 and 4 and 4.
This is the same failure class as #2368, which gives
do_narythe spec default for an omittedm:chr; these five crash a step earlier, on the properties element itself. The fix reads the child through a helper that substitutes an empty one, so every property falls through to the default it already has.Reproduction
New test file, on unmodified
main(packages/markitdown):The unit failures are
KeyError: 'fPr'and friends; the end-to-end one is the whole document going dark:The one test that passes before and after is the pin:
<m:dPr>with an explicitbegChr/endChrstill converts to\left[x\right]rather than the default parentheses.With the fix:
Verification
No fixture is modified: the end-to-end test rebuilds
equations.docxin memory.blackreports both touched files unchanged.