Refs #36769 -- Avoided visiting grandchild nodes in XML Deserializer.

The only use case for visiting grandchild nodes turned out to be to
support an unintentionally invalid fixture in the test suite.

The invalid fixture added in #36969 was modeled on fixture9.xml in
dae08cf55b, so that is corrected as well
in this commit, where the test will still pass.
This commit is contained in:
Jacob Walls
2026-01-07 16:23:32 -05:00
parent 1a70889d58
commit a25158f5cc
2 changed files with 6 additions and 10 deletions

View File

@@ -439,17 +439,13 @@ class Deserializer(base.Deserializer):
)
def check_element_type(element):
return element.nodeType in (element.TEXT_NODE, element.CDATA_SECTION_NODE)
def getInnerText(node):
"""Get the inner text of a DOM node and any children one level deep."""
# inspired by
# https://mail.python.org/pipermail/xml-sig/2005-March/011022.html
return "".join(
[
element.data
for child in node.childNodes
for element in (child, *child.childNodes)
if element.nodeType in (element.TEXT_NODE, element.CDATA_SECTION_NODE)
]
[child.data for child in node.childNodes if check_element_type(child)]
)

View File

@@ -3,7 +3,7 @@
<object pk="1" model="fixtures.person">
<field type="CharField" name="name">
<natural>Django <em>pony</em></natural>
Django <em>pony</em>
</field>
</object>