Skip to content

fix(docx): resolve math converter crash on empty runs in OMML to LaTeX#2204

Open
saitejabandaru-in wants to merge 1 commit into
microsoft:mainfrom
saitejabandaru-in:fix/docx-math-empty-run
Open

fix(docx): resolve math converter crash on empty runs in OMML to LaTeX#2204
saitejabandaru-in wants to merge 1 commit into
microsoft:mainfrom
saitejabandaru-in:fix/docx-math-empty-run

Conversation

@saitejabandaru-in

Copy link
Copy Markdown

Summary

Resolves #2188.

Root Cause

In omml.py, the do_r function retrieves text from a math run element via elm.findtext("./{0}t".format(OMML_NS)). If a math run (<m:r>) has formatting properties (<m:rPr/>) but no <m:t> text child (which some Word editors or copy-pasted equations produce), findtext() returns None.
Attempting to iterate over None (for s in None) raises TypeError: 'NoneType' object is not iterable.

Because math preprocessing in pre_process_docx() runs on the entire document.xml file in a single try-except block, a single crash in do_r silently drops all equations in the document, falling back to original unconverted XML.

Changes

  • Guard against None return values in do_r() before iteration.
  • Add a unit test (test_docx_empty_math_run) in test_module_misc.py using a mock XML structure to verify the fix works and prevents regressions.

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.

bug: DOCX math converter crashes (and silently drops all equations) when a math run has no text child

1 participant