A processing instruction with no target passes validation, then the builder prints invalid XML

Abierto Apto para principiantes
#927 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

@bardrop ya está trabajando en esto.

Desde el 17/11/2026.

  • #928 de @bardrop — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, node.js

Línea de trabajo

Empieza por la ruta de validación de las instrucciones de procesamiento en XMLValidator y compara después su tratamiento de <?x?> y <? ?> con la gramática de PI de XML descrita en el issue. Comprueba el comportamiento del parser y del builder usando el ejemplo de Node.js proporcionado. Se considera terminado cuando la validación rechaza los casos de target no válidos, o el parsing los omite, de modo que el builder no produzca XML no válido.

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

Descripción

  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?
  • Have you checked the docs for helpful APIs and examples?
Description

Hello,

While fuzzing [email protected] (the latest version) with Termo, a fuzzer I'm developing, I found that XMLValidator accepts a processing instruction with no target name (<?>x?>). XMLParser then returns a node with an empty tag name, and XMLBuilder turns it into <></>, which is not XML:

// [email protected], Node.js v26.13.0
const { XMLValidator, XMLParser, XMLBuilder } = require('fast-xml-parser');
const options = { ignoreAttributes: false, preserveOrder: true };
const input = '<?>x?><r/>';
console.log(XMLValidator.validate(input));            // true
const parsed = new XMLParser(options).parse(input);
console.log(JSON.stringify(parsed));                  // [{"":[{"#text":""}]},{"r":[]}]
const built = new XMLBuilder(options).build(parsed);
console.log(built);                                   // <></><r></r>
console.log(XMLValidator.validate(built) === true);   // false

Without a target (<?>) validation already fails as it should. With a body (<?>x?>) it passes. The XML spec requires a name right after <? (PI ::= '<?' PITarget (S ...)? '?>').

<? ?><r/> is similar: it validates, and parses into a node named "?", which the builder prints as <??>.

Expected: the validator rejects a processing instruction with no target (or else the parser skips it), so the builder never prints an element with an empty name.

Happy to test a fix against these inputs if it helps.

If you'd like me to keep fuzzing fast-xml-parser (other parts of the API, or re-checking after a fix), feel free to reach out. I'd be glad to keep working on it with you.

Thanks!

Lenguaje dominante
JavaScript
Estrellas
3.1k
Forks
410
Merge medio
4 d 15 h
PR fusionados (30 d)
8

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.