Numeric character references (A, A) are not decoded unless htmlEntities is enabled
I maintainer di solito rispondono entro 4 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 64/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
- Ambito
- backend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- JavaScript
- Stelle
- 3.1k
- Fork
- 400
- Merge medio
- 3g 9h
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NaturalIntelligence/fast-xml-parser
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 commenti ·
I maintainer di solito rispondono entro 4 giorni
-
ignoreDeclaration does not ignore lower case doctype declarationForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NaturalIntelligence/fast-xml-parser#870 · 2 commenti ·
I maintainer di solito rispondono entro 4 giorni
-
Enhance type definition for XMLParser `isArray` option when using TypeScriptForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
NaturalIntelligence/fast-xml-parser#803 · 21 commenti · 2 reazioni ·
I maintainer di solito rispondono entro 4 giorni
-
Feature-Request
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
NaturalIntelligence/fast-xml-parser#779 · 9 commenti ·
I maintainer di solito rispondono entro 4 giorni
Tutte le issue di NaturalIntelligence/fast-xml-parser
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
highcharts/highcharts-react#594 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno