Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#892 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
64/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, node.js
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
JavaScript
Estrellas
3.1k
Forks
400
Merge medio
3 d 9 h
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de NaturalIntelligence/fast-xml-parser

Todos los issues de NaturalIntelligence/fast-xml-parser

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.