Skip to content

Commit 8d012fe

Browse files
committed
refactor(parser): remove dead namespaced find in parse_invoke
The `child.find("{http://www.w3.org/2005/07/scxml}scxml")` call was unreachable because `strip_namespaces()` always runs before `parse_invoke()`. Replaced with direct `child.find("scxml")`. Also added a test for unknown child elements inside `<invoke>`.
1 parent 085fee7 commit 8d012fe

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

statemachine/io/scxml/parser.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,8 @@ def parse_invoke(element: ET.Element) -> InvokeDefinition:
442442
location = child.attrib.get("location")
443443
params.append(Param(name=name, expr=expr, location=location))
444444
elif child.tag == "content":
445-
# Check for inline <scxml> element
446-
scxml_child = child.find("{http://www.w3.org/2005/07/scxml}scxml")
447-
if scxml_child is None:
448-
scxml_child = child.find("scxml")
445+
# Check for inline <scxml> element (namespaces already stripped)
446+
scxml_child = child.find("scxml")
449447
if scxml_child is not None:
450448
# Serialize the inline SCXML back to string for later parsing
451449
content = ET.tostring(scxml_child, encoding="unicode")

tests/test_scxml_units.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,22 @@ def test_invoke_with_inline_scxml_no_namespace(self):
899899
invoke_def = definition.states["s1"].invocations[0]
900900
assert "<final" in invoke_def.content
901901

902+
def test_invoke_with_unknown_child_element(self):
903+
"""Unknown child elements inside <invoke> are silently ignored."""
904+
scxml = """
905+
<scxml xmlns="http://www.w3.org/2005/07/scxml" initial="s1">
906+
<state id="s1">
907+
<invoke type="http://www.w3.org/TR/scxml/">
908+
<param name="x" expr="1"/>
909+
<unknownElement/>
910+
</invoke>
911+
</state>
912+
</scxml>
913+
"""
914+
definition = parse_scxml(scxml)
915+
invoke_def = definition.states["s1"].invocations[0]
916+
assert len(invoke_def.params) == 1
917+
902918
def test_invoke_with_empty_content(self):
903919
"""<invoke> with empty <content/> results in content=None."""
904920
scxml = """

0 commit comments

Comments
 (0)