Incorrect parsing of `<`angle brackets `>` as text characters
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript
- Domain
- tooling
Research direction
Start by reproducing both examples with XMLParser.parse using preserveOrder, then inspect the parser entry point and the token/name handling reached by these inputs. Use XMLBuilder.build to verify the result. Done means invalid angle-bracket sequences remain text and valid XML structure is preserved in both cases.
Written by the indexing model from the issue text.
Description
- 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.
- Dominant language
- JavaScript
- Stars
- 3.1k
- Forks
- 398
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NaturalIntelligence/fast-xml-parser
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 comment ·
Maintainers usually reply within 3 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 comments ·
Maintainers usually reply within 3 days
-
ignoreDeclaration does not ignore lower case doctype declarationMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NaturalIntelligence/fast-xml-parser#870 · 2 comments ·
Maintainers usually reply within 3 days
-
Enhance type definition for XMLParser `isArray` option when using TypeScriptMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 52/100
NaturalIntelligence/fast-xml-parser#803 · 21 comments · 2 reactions ·
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
NaturalIntelligence/fast-xml-parser#766 · 4 comments ·
Maintainers usually reply within 3 days
All issues in NaturalIntelligence/fast-xml-parser
Similar issues
-
Access-request approve silently discards the decider's note (decision_note written only on deny)Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Uuriko/project-room#3378 ·
Maintainers usually reply within 1 day
-
Notifications pagination accepts NaN and negative LIMIT/OFFSETPossibly taken @Senthil455 claimed this today. OpenBUGS MEDIUM
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
elixpo/blogs.elixpo#419 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
immich-app/immich#32426 ·
Maintainers usually reply within 1 day