Repository navigation
fix(docx): skip non-element XML nodes - #4564
chriscoveries wants to merge 1 commit into
Conversation
Signed-off-by: chriscoveries <212684707+chriscoveries@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @chriscoveries, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
| ) -> tuple[DoclingDocument, list[RefItem]]: | ||
| added_elements = [] | ||
| for element in body: | ||
| if not isinstance(element.tag, str): |
There was a problem hiding this comment.
Should we have this text in a ContentLayer. I am generally not a fan of omitting text, unless it is format related.
|
@chriscoveries @loickouao @PeterStaar-IBM: #4564 and #4584 fix the same crash. XML comment and processing-instruction nodes in a DOCX part are not elements, so
Proposal: continue with #4584 as the single fix, and close #4564, with credit to @chriscoveries for the first fix and the test case. Before #4584 can merge, it still needs:
@chriscoveries: if the body-level test in #4564 covers a case that #4584 does not, please say so here, and it can move into #4584. |
Problem
WordprocessingML bodies can contain XML comments or processing instructions between ordinary document elements. The DOCX backend passes every child node to
etree.QName, but lxml represents these non-element nodes with callable tags.etree.QNameraisesValueError, aborting the entire conversion.Reproducer
Create a DOCX with a paragraph before and after an XML comment or processing instruction in
word/document.xml, then convert it withMsWordDocumentBackend. Before this change, conversion fails while walking the document body.The regression test constructs this DOCX entirely at test time and does not add a binary fixture.
Fix
Skip child nodes whose lxml tag is not a string before performing QName or XPath processing. This preserves existing handling for WordprocessingML elements while safely ignoring comments and processing instructions.
Tests
Commit:
f4c766cd178248e188312b9acd50bca372749528Signed-off-by: chriscoveries 212684707+chriscoveries@users.noreply.github.com