XMLValidator accepts raw < and & in attribute values

Open Beginner friendly
#900 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

@jeromeyyy is already working on this.

Since Nov 4, 2026.

  • #913 by @jeromeyyy — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
data

Research direction

Start in the validator's validateAttributeString function, which the issue says receives the quoted value from the attribute token scanner but never checks it for raw '<' or malformed '&' references. Run the three inputs from the issue through XMLValidator.validate and parse(xml, true) to confirm the current behaviour. Done means the first two inputs fail validation, the &amp; control still passes, and existing tests stay green.

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 the online tool?
  • Have you checked the docs for helpful APIs and examples?
Description

On 5.11.2 (current master at cf66a9658004553bc740616e6c7a4912e7e9aab6), XMLValidator accepts raw ampersands and less-than signs inside quoted attribute values. XML 1.0's AttValue grammar excludes both literal characters there; an ampersand must begin a reference. This concerns attribute values, whereas #214 reported a stray ampersand in element text.

Input
<a x="&"/>
<a x="<"/>
<a x="&amp;"/>

The last input is a valid control.

Code
const { XMLParser, XMLValidator } = require('fast-xml-parser');

for (const xml of ['<a x="&"/>', '<a x="<"/>', '<a x="&amp;"/>']) {
  console.log(xml, XMLValidator.validate(xml));
}
console.log(new XMLParser({ ignoreAttributes: false }).parse('<a x="&"/>', true));
Output

XMLValidator.validate returns true for all three inputs. Parsing the raw-ampersand input with validation enabled returns { a: { '@_x': '&' } }. The official online validator also reports "Valid XML" for both malformed inputs.

Expected data

The first two inputs should return a validation error, and parse(xml, true) should reject them. The escaped control should remain valid. The attribute token scanner extracts the quoted value, but validateAttributeString does not check that value for raw '<' or malformed '&' references.

Would you like to work on this issue?

  • Yes
  • No
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.