A processing instruction with no target passes validation, then the builder prints invalid XML
Maintainers usually reply within 4 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, testing-qa
Research direction
Start with the processing instruction validation path in XMLValidator, then compare its handling of <?x?> and <? ?> with the XML PI grammar described in the issue. Check the parser and builder behavior using the supplied Node.js example. Done means validation rejects the invalid target cases, or parsing skips them, so the builder does not produce invalid XML.
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
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!
- Dominant language
- JavaScript
- Stars
- 3.1k
- Forks
- 410
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 8
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
-
XMLValidator accepts double hyphens inside commentsPossibly taken @Sskift claimed this 16 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NaturalIntelligence/fast-xml-parser#903 · 3 comments ·
Maintainers usually reply within 4 days
-
XMLValidator accepts raw < and & in attribute valuesPossibly taken @jeromeyyy claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NaturalIntelligence/fast-xml-parser#900 · 3 comments ·
Maintainers usually reply within 4 days
-
getMetaDataSymbol() declares a boxed SymbolPossibly taken @chiragbitoni claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 comment ·
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 comments ·
Maintainers usually reply within 4 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 4 days
All issues in NaturalIntelligence/fast-xml-parser
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Extended search drops any query term that contains a line breakPossibly taken @goranai claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day