Numeric character references (A, A) are not decoded unless htmlEntities is enabled
Maintainers usually reply within 4 days
Nobody has claimed this yet.
- #893 by @guocn — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 64/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend
Research direction
Start by reading OrderedObjParser and its EntityDecoder construction, especially the numericAllowed option mentioned in the issue; then inspect the existing entity-decoding tests. Reproduce the examples for element text and attribute values with default options, and run the relevant parser tests. Done means numeric XML character references decode without enabling htmlEntities, while the existing named-entity behavior remains covered.
Written by the indexing model from the issue text.
Description
With default options, processEntities is true and the five predefined XML entities (<, >, &, ", ') are decoded as expected. Numeric character references, however, are silently left as literal text unless htmlEntities: true is passed:
const { XMLParser } = require('fast-xml-parser');
const parser = new XMLParser(); // processEntities defaults to true
parser.parse('<r><>&</r>');
// { r: '<>&' } -- named entities decoded
parser.parse('<r>AB</r>');
// { r: 'AB' } -- numeric refs NOT decoded (expected: { r: 'AB' })
parser.parse('<r a="A"/>', { ignoreAttributes: false });
// attributes affected the same way
new XMLParser({ htmlEntities: true }).parse('<r>AB</r>');
// { r: 'AB' } -- only decoded when htmlEntities is on
Numeric character references are not HTML entities - they are part of core XML. Per the XML 1.0 spec (section 4.1, "Character and Entity References"), a well-formed XML processor must recognize &#...; and &#x...; references in content and attribute values, independent of any HTML entity table.
Looking at the source, this seems to come from OrderedObjParser wiring numericAllowed to the htmlEntities option when constructing the EntityDecoder:
this.entityDecoder = new EntityDecoder({
namedEntities: { ...namedEntities, ...externalEntities },
numericAllowed: this.options.htmlEntities, // <-- ties XML char refs to the HTML entities option
...
});
So a user who parses XML with default options (and htmlEntities defaults to false) gets raw A sequences in their data, while named XML entities are decoded. I ran into this with a feed that encodes non-ASCII characters as numeric refs.
Tested on fast-xml-parser 5.11.2 (npm latest) with Node 22. The same behavior exists in 4.x, so it may be intentional - but if so, it would be great to have it documented next to processEntities, since the current default contradicts XML spec compliance.
- Dominant language
- JavaScript
- Stars
- 3.1k
- Forks
- 410
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 8
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NaturalIntelligence/fast-xml-parser
-
A processing instruction with no target passes validation, then the builder prints invalid XMLPossibly taken @bardrop claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NaturalIntelligence/fast-xml-parser#927 · 2 comments ·
Maintainers usually reply within 4 days
-
XMLValidator accepts double hyphens inside commentsPossibly taken @Sskift claimed this 16 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NaturalIntelligence/fast-xml-parser#903 · 3 comments ·
Maintainers usually reply within 4 days
-
XMLValidator accepts raw < and & in attribute valuesPossibly taken @jeromeyyy claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NaturalIntelligence/fast-xml-parser#900 · 3 comments ·
Maintainers usually reply within 4 days
-
getMetaDataSymbol() declares a boxed SymbolPossibly taken @chiragbitoni claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 comment ·
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 comments ·
Maintainers usually reply within 4 days
All issues in NaturalIntelligence/fast-xml-parser
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Extended search drops any query term that contains a line breakPossibly taken @goranai claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day