Visitar URL original
XMLValidator accepts raw < and & in attribute values · Issue #900 · NaturalIntelligence/fast-xml-parser · GitHub
Skip to content

XMLValidator accepts raw < and & in attribute values #900

Open

Description

@agammann
  • 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 cf66a96), 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

Activity

  1. aliassar commented on Nov 3, 2026

    @aliassar

    Can I work on this?

  2. amitguptagwl commented on Nov 3, 2026

    @amitguptagwl
    Member

    Have you checked fast-xml-validator?

  3. aliassar commented on Nov 3, 2026

    @aliassar

    Just tried it. fast-xml-validator 1.4.2 has the same issue, SyntaxValidator.validate('<a x="<"/>') and '<a x="&"/>' both return true. Happy to send the fix there instead if that is where validator fixes should go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions