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

Open Beginner friendly
#927 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

@bardrop is already working on this.

Since Nov 17, 2026.

  • #928 by @bardrop — open

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

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NaturalIntelligence/fast-xml-parser

All issues in NaturalIntelligence/fast-xml-parser

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.