Skip to content

fix: guard against missing oMath element in DOCX math converter (#1979)#1995

Open
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-issue-1979-missing-omath-crash
Open

fix: guard against missing oMath element in DOCX math converter (#1979)#1995
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-issue-1979-missing-omath-crash

Conversation

@hanhan761
Copy link
Copy Markdown

Summary

When a DOCX file contains a malformed math equation where the \oMath\ child element is missing, _convert_omath_to_latex()\ passes \None\ to \oMath2Latex(), which raises \TypeError\ because \None\ is not iterable.

This change adds a \None\ check after \math_root.find()\ and returns an empty string as a fallback, allowing the conversion to continue without crashing.

Issue

Fixes #1979

Verification

  • \ est_docx_malformed_equations\ — creates a synthetic DOCX with an \oMathPara\ containing no \oMath\ child and an empty inline \oMath, then verifies the converter handles both without crashing and returns expected text.
  • All 109 existing vector tests pass.
  • All existing docx module tests pass.

…osoft#1979)

Add a None check in _convert_omath_to_latex() to return an empty
string when the math element is missing, instead of passing None to
oMath2Latex() which raises TypeError.

Fixes microsoft#1979
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 when oMath element is missing in malformed equations

1 participant