Skip to content

fix: stop node namespace prefix parameter ordering in readStopNodeData#818

Open
iruizsalinas wants to merge 1 commit intoNaturalIntelligence:masterfrom
iruizsalinas:fix/stopnode-namespace-prefix
Open

fix: stop node namespace prefix parameter ordering in readStopNodeData#818
iruizsalinas wants to merge 1 commit intoNaturalIntelligence:masterfrom
iruizsalinas:fix/stopnode-namespace-prefix

Conversation

@iruizsalinas
Copy link
Copy Markdown

Purpose / Goal

Fix incorrect parameter ordering in readStopNodeData that breaks stop node tracking when the tag has a namespace prefix.

Type

  • Bug Fix

readStopNodeData calls readTagExp(xmlData, i, '>') at line 760, but '>' ends up in the removeNSPrefix parameter instead of closingChar. Since it's truthy, namespace prefixes get stripped from opening tags inside the stop node, while closing tags keep them. This throws off openTagCount because opens and closes no longer match.

const parser = new XMLParser({ stopNodes: ["root.ns:code"] });
const result = parser.parse(
  "<root><ns:code>safe <ns:code>nested</ns:code> still raw</ns:code></root>"
);
// result.root["ns:code"] should be "safe <ns:code>nested</ns:code> still raw"
// but instead the stop node exits early at the inner </ns:code>

The fix is changing readTagExp(xmlData, i, '>') to readTagExp(xmlData, i, false) since closingChar already defaults to ">".

@amitguptagwl
Copy link
Copy Markdown
Member

Thanks for your effort and time. Let me test it with some tests and then I'll check the PR. Probably on coming monday

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.

2 participants