Skip to content

XMLValidator accepts double hyphens inside comments #903

Open

Description

@agammann
  • Are you running the latest version? (5.11.2, master at cf66a9658004553bc740616e6c7a4912e7e9aab6)
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration? (default options)
  • Did you try online tool? (it reports Valid XML for the 22-byte sample)
  • Have you checked the docs for helpful APIs and examples?

Description

XMLValidator.validate accepts a comment containing -- before the closing delimiter. XML 1.0 comments cannot contain a double hyphen within the comment text. Python xml.etree.ElementTree rejects the same input as not well-formed at column 12.

Input

<a><!--foo--bar--></a>

Code

const { XMLValidator, XMLParser } = require("./lib/fxp.cjs");
for (const xml of ["<a><!--foo--bar--></a>", "<a><!--ok--></a>"]) {
  console.log(xml, XMLValidator.validate(xml), new XMLParser().parse(xml, true));
}

Output

Both inputs return true from XMLValidator.validate and parse as { a: "" }. The online tool also reports Valid XML for the malformed sample.

Expected data

The malformed comment should be rejected; <a><!--ok--></a> should remain valid.

Would you like to work on this issue?

  • Yes
  • No

Activity

  1. Sskift commented on Nov 2, 2026

    @Sskift
    Contributor

    I have a tested patch for this issue and am preparing a PR. It rejects invalid double hyphens in both validator comment-scanning paths, with coverage for comments before, inside and after the root. Prepared with Codex assistance, automated regression tests, and independent agent review.

  2. amitguptagwl commented on Nov 3, 2026

    @amitguptagwl
    Member

    plz check fast-xml-validator once

  3. agammann commented on Nov 4, 2026

    @agammann
    Author

    I checked the separate fast-xml-validator SyntaxValidator.validate on main at 335fcaf (package.json 1.4.2, Node 24.22.1). It returns true for the malformed <a><!--foo--bar--></a> and for the valid <a><!--ok--></a> control. This also reproduces in the separate validator.

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