Skip to content

crawl/sitemap-valid passes a sitemap with mismatched or unclosed tags: the parser never checks well-formedness #760

Closed

Description

@nc9

fast-xml-parser, which parseSitemap (packages/crawler/src/sitemaps.ts) uses, does not check that the XML is well formed. A mismatched closing tag (<loc>https://example.com/a</loc></lox>) or an element left open parses without an error, so crawl/sitemap-valid reports Sitemap XML syntax is valid for a file that a strict consumer would reject. XMLValidator.validate from the same package reports these, and a raw &.

Found while reviewing #687 (PR #757), which makes a raw < inside a field count as an error, but only where the parser happens to read it as a child element.

Acceptance Criteria

  • A sitemap with a mismatched closing tag, an unclosed element, or a raw & in a <loc> gets a crawl/sitemap-valid syntax error naming the problem, and the URLs the parser can still read are still read.
  • Well-formed sitemaps, including ones with CDATA, comments, xhtml:link and image:image extensions, get no new error.
  • The well-formedness check stays linear in the body size on a 50 MB sitemap (time it at n, 2n, 4n).
  • Parser tests cover each case above.

Activity

  1. added
    bug
    P3
    size: M
    on Oct 14, 2026
  2. nc9 commented on Oct 16, 2026

    @nc9
    ContributorAuthor

    Fixed in #892. Once a sitemap root parses, parseSitemap runs XMLValidator. It records XML is not well formed: <reason> (line L, column C) for a mismatched closing tag, an unclosed element or a raw & in element text, and keeps the URLs it can read. These get no new error: well-formed files with CDATA, comments, xhtml:link/image:image, escapes, a BOM or leading whitespace. Files with an internal DTD subset are not checked. Validation timed at 168/326/672 ms for 12.5/25/50 MB, and a test pins the linear ratio. The tests are in packages/crawler/tests/sitemap-well-formed-760.test.ts.

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

    P3bugsize: M

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions