Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Numeric character references (A, A) are not decoded unless htmlEntities is enabled

Aperta
#892 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

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>&lt;&gt;&amp;</r>');
// { r: '<>&' }  -- named entities decoded

parser.parse('<r>&#65;&#x42;</r>');
// { r: '&#65;&#x42;' }  -- numeric refs NOT decoded (expected: { r: 'AB' })

parser.parse('<r a="&#65;"/>', { ignoreAttributes: false });
// attributes affected the same way

new XMLParser({ htmlEntities: true }).parse('<r>&#65;&#x42;</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 &#65; 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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NaturalIntelligence/fast-xml-parser

Tutte le issue di NaturalIntelligence/fast-xml-parser

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.