Incorrect parsing of `<`angle brackets `>` as text characters
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- tooling
Línea de trabajo
Comienza reproduciendo ambos ejemplos con XMLParser.parse usando preserveOrder; después, inspecciona el punto de entrada del parser y el manejo de tokens/nombres al que llegan estas entradas. Usa XMLBuilder.build para verificar el resultado. Se considera terminado cuando las secuencias de corchetes angulares no válidas permanecen como texto y la estructura XML válida se conserva en ambos casos.
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
I encountered a case where a text content like <...> inside a tag is incorrectly handled by the parser. The parser tries to interpret this as a tag name and breaks the tree structure. This is also applicable to the symbol \U+2026 Horizontal Ellipsis
What does <...> mean?
In text, <...> usually means something has been intentionally left out. It’s a placeholder that implies omitted words, omitted text that isn’t being shown, quoted, or repeated
However, the . symbol can indeed be used in the XML tag name, but only if it is not the starting character (NameStartChar in spec). And the ellipsis symbol seems to be invalid for NameChar. Please look at the Names and Tokens section here https://www.w3.org/TR/xml/#sec-common-syn
Also, while writing this issue, I tried using only the angle bracket characters individually and saw strange behavior. I've described this below as a second case.
I assume that the correct parser behavior if the angle brackets don't form a valid tag name according to XML specification would be to leave the angle bracket characters in the #text element or escape them in entities.
Input
Code
const xmlParser = new XMLParser({
preserveOrder: true,
allowBooleanAttributes: true,
ignoreAttributes: false,
ignoreDeclaration: true,
});
const firstCase = `<?xml version="1.0"?>
<root>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies <...> Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis. <...> Nulla gravida erat a tortor sollicitudin laoreet.</p>
<foo></foo>
</root>`;
const secondCase = `<?xml version="1.0"?>
<root>
<p>if (1 < 3) return text;</p>
</root>
`;
const jObj = xmlParser.parse(firstCase); // check first and second case
const xmlBuilder = new XMLBuilder({
ignoreAttributes: false,
preserveOrder: true,
});
const xmlContent = xmlBuilder.build(jObj);
console.log(xmlContent);
Output
In the first case:
jObj
[
{
"root": [
{
"p": [
{
"#text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies"
},
{
"...": [
{
"#text": "Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis."
},
{
"...": [
{
"#text": "Nulla gravida erat a tortor sollicitudin laoreet."
}
]
},
{
"foo": []
}
]
}
]
}
]
}
]
<root><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies<...>Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis.<...>Nulla gravida erat a tortor sollicitudin laoreet.</...><foo></foo></...></p></root>
In the second case:
jObj
[
{
"root": [
{
"p": [
{
"#text": "if (1"
},
{
"": [],
":@": {
"@_3)": true,
"@_return": true,
"@_text;": true,
"@_</p": true
}
}
]
}
]
}
]
<root><p>if (1< 3) return text; </p></></p></root>
expected data
In the first case:
<root><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies <...> Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis. <...> Nulla gravida erat a tortor sollicitudin laoreet.</p><foo></foo></root>
In the second case:
<root><p>if (1 < 3) return text;</p></root>
Would you like to work on this issue?
- Yes
- No
Bookmark this repository for further updates. Visit SoloThought to know about recent features.
- Lenguaje dominante
- JavaScript
- Estrellas
- 3.1k
- Forks
- 400
- Merge medio
- 3 d 9 h
- PR fusionados (30 d)
- 1
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de NaturalIntelligence/fast-xml-parser
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 comentarios ·
Los mantenedores suelen responder en 3 días
-
ignoreDeclaration does not ignore lower case doctype declarationQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NaturalIntelligence/fast-xml-parser#870 · 2 comentarios ·
Los mantenedores suelen responder en 3 días
-
Enhance type definition for XMLParser `isArray` option when using TypeScriptQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
NaturalIntelligence/fast-xml-parser#803 · 21 comentarios · 2 reacciones ·
Los mantenedores suelen responder en 3 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
NaturalIntelligence/fast-xml-parser#766 · 4 comentarios ·
Los mantenedores suelen responder en 3 días
Todos los issues de NaturalIntelligence/fast-xml-parser
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Add: EUROTV NEWSAbiertochannels:add check:passed
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
curriculum documentation quality
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
githubnext/gh-aw-workshop#4638 ·
Los mantenedores suelen responder en 1 día
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
openclaw/openclaw-enterprise#2571 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
fabriziosalmi/certmate#1247 ·
Los mantenedores suelen responder en 1 día