Repository navigation
fix(sitemaps): report sitemaps that are not well-formed XML and lastmod values outside W3C Datetime (#760, #781) - #892
Conversation
|
Reviewed the diff (well-formedness check in sitemaps.ts, lastmod format checks in sitemap-valid.ts, docs, changelog, tests). I did not run the test suite. I found no blocking problems.
Test coverage is good. It covers the mismatched tag, the unclosed element, the raw &, position offsets, DOCTYPE skipping, CDATA and well-formed regressions, the lastmod formats, the no-zone case and sample truncation. |
|
Review triage, no code change:
|
2094a52 to
d953b29
Compare
|
Review of #892 (sitemap well-formedness and lastmod format checks). I read the diff and confirmed that Overall the change looks sound. The parser still reads the URLs, the new error is additive, and
No blocking issues found. |
…od values outside W3C Datetime (#760, #781) parseSitemap runs fast-xml-parser's XMLValidator once a sitemap root parses and records 'XML is not well formed: <reason> (line L, column C)' for a mismatched closing tag, an element left open or a raw & in element text; the URLs it can read are kept, a page-labelled body with only that error stays a sitemap, leading whitespace is tolerated and a file with an internal DTD subset is not checked (the validator misreads those). crawl/sitemap-valid adds sitemap-lastmod-format (not W3C Datetime) and sitemap-lastmod-zone (a datetime with no zone) warnings with sampled URLs and values; no pass check, so scores without lastmod problems are unchanged. Signed-off-by: Nik Cubrilovic <[email protected]>
d953b29 to
84e980b
Compare
|
Review of #892 (sitemap well-formedness and lastmod format checks). I read the diff and confirmed that
I found no correctness, security or performance problems that should block the merge. Docs, changelog and tests cover the new behaviour. |
Two sitemap findings
crawl/sitemap-validmissed.Closes #760, closes #781.
#760: sitemaps that are not well-formed XML (
packages/crawler/src/sitemaps.ts)fast-xml-parser reads past a mismatched closing tag, an element left open and a raw
&, socrawl/sitemap-validpassed a file a strict consumer rejects. Once a<urlset>or<sitemapindex>root parses,parseSitemapnow also runs the same package'sXMLValidator. On failure it records, first among the sitemap's errors:XML is not well formed: <reason> (line <L>, column <C>)<?xmlis tolerated. It is outside the spec, but common, and the walk already reads past it.<!DOCTYPE urlset [ … ]>) is not checked. The validator misreads a quoted>in the subset and rejects long entity names, so a valid file would fail. Such files are rare in sitemaps, and the parser refuses declared entities anyway. The subset is found by a linear scan, so a prolog comment cannot hide it and a body of repeated<!DOCTYPEcosts its length.decodeSitemapBody, a body whose only errors are well-formedness errors still counts as a sitemap. Without that, a page-labelled body that opens with another element would have lost its URLs.&in an attribute (anxhtml:linkhref) is not caught. The validator does not check attribute escapes, and the docs say "element text".Tests are in
packages/crawler/tests/sitemap-well-formed-760.test.ts:&;xhtml:linkandimage:image, escapes, a BOM, leading whitespace, an index;In the #687 test, the raw
<cases now also expect the well-formedness error first.#781: lastmod values outside W3C Datetime (
packages/rules/src/crawl/sitemap-valid.ts)Two new warning checks, each with a sample of URLs and
lastmod "<value>"labels (up to 50) and the exact count intotal:sitemap-lastmod-format:N sitemap lastmod value(s) are not in W3C Datetime format. Examples:2024/09/10,2024-9,2024-09-31,Tue, 10 Sep 2024 12:00:00 GMT.sitemap-lastmod-zone:N sitemap lastmod datetime(s) have no time zone, for2024-09-10T12:00:00. It reads as a date, just not in a known zone.W3C values are not reported:
2024,2024-09,2024-09-10,…T12:00Z,…T12:00:00.123+02:00. There is no pass check: one would add a passed check to every audit's score for this rule. So scores for sites without lastmod problems are unchanged, and the codex review measured how a pass check would dilute a failing rule's score. The tests are inpackages/rules/tests/sitemap-lastmod-format-781.test.ts.Docs (
docs/rules/crawl/sitemap-valid.mdx): the new error and both checks, with their messages as templates, and how to fix them. CHANGELOG: one Fixed entry and one Added entry.Checks
tsgo --noEmit: packages/crawler and packages/rules are clean.bun test:packages/crawler/tests/sitemap*files plus the new one: 108 pass;packages/rulessitemap-lastmod-format-781, sitemap-valid and sitemap-caps: 21 pass.bun docs/scripts/check-links.tsandtangly check --strict: pass.notASitemapinteraction: fixed.&claim: narrowed in the docs.Docs: in this PR. Agent skill: no change needed.