Skip to content

fix: stopNodes should preserve text content as string (#795)#797

Open
abhu85 wants to merge 1 commit intoNaturalIntelligence:masterfrom
abhu85:fix/stopnodes-preserve-string-795
Open

fix: stopNodes should preserve text content as string (#795)#797
abhu85 wants to merge 1 commit intoNaturalIntelligence:masterfrom
abhu85:fix/stopnodes-preserve-string-795

Conversation

@abhu85
Copy link

@abhu85 abhu85 commented Mar 7, 2026

Summary

  • Fixes stopNodes content being parsed as numbers/booleans instead of remaining as strings
  • <a>6</a> with stopNodes: ["*.a"] now returns { a: "6" } instead of { a: 6 }

Problem

When using stopNodes option, numeric and boolean-like text content was being converted to JavaScript numbers/booleans. According to the documentation, stopNodes should preserve content as raw text.

Reproduction (from #795):

const parser = new XMLParser({ stopNodes: ["*.a"] });
console.log(typeof parser.parse("<a>6</a>").a); // "number" - should be "string"

Solution

Added doNotParseTagValue parameter to parseTextData function and set it to true when processing stopNode content. This skips the parseValue call that converts strings to numbers/booleans, while still allowing tagValueProcessor to work for user customization.

Test Plan

  • All 282 existing tests pass
  • Added regression test covering: numeric strings, boolean strings ("true"/"false"), negative/decimal numbers, scientific notation

Compatibility

  • No breaking changes
  • Backwards compatible - existing tagValueProcessor behavior preserved

Fixes #795

…gence#795)

When using stopNodes option, numeric and boolean-like text content
was being converted to JavaScript numbers/booleans (e.g., "6" became 6).

This fix ensures stopNode content remains as raw string text, which is
the expected behavior since stopNodes are meant to preserve unparsed
content.

Changes:
- Add doNotParseTagValue parameter to parseTextData function
- Pass true for this parameter when processing stopNode content
- Add regression test for numeric/boolean/scientific notation strings

Fixes NaturalIntelligence#795
@abhu85
Copy link
Author

abhu85 commented Mar 9, 2026

Hi @AmitagPro 👋

Friendly ping on this PR. It fixes the stopNodes option to preserve text content as a string (#795), with tests covering the fix.

All CI checks are passing. Would appreciate a review when you have a moment. Thanks!

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.

stopNodes still parses numbers

1 participant