XMLValidator accepts raw < and & in attribute values
Maintainers usually reply within 4 days
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 & 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="&"/>
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="&"/>']) {
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
- 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
-
A processing instruction with no target passes validation, then the builder prints invalid XMLPossibly taken @bardrop claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NaturalIntelligence/fast-xml-parser#927 · 2 comments ·
Maintainers usually reply within 4 days
-
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
-
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