Skip to content

fix(crawler): a bare-year sitemap lastmod no longer fails the whole sitemap #687 - #757

Merged
nc9 merged 3 commits into
mainfrom
fix/sitemap-bare-year-lastmod-687
Oct 14, 2026
Merged

nc9 merged 3 commits into
mainfrom
fix/sitemap-bare-year-lastmod-687

Conversation

@nc9

@nc9 nc9 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #687.

What changed

parseSitemap (packages/crawler/src/sitemaps.ts) ran fast-xml-parser with its default value parsing, which hands a numeric text node through as a number. <lastmod>2024</lastmod>, a valid W3C Datetime, became the number 2024, .trim() threw, and crawl/sitemap-valid reported the whole file as an error starting Parse error: entry.lastmod?.trim is not a function, with none of its URLs read.

  • Values stay text: the parser now runs with parseTagValue: false, so every value is the text the sitemap wrote (2024 stays "2024", <priority>0.80</priority> still becomes 0.8 through the existing parseFloat). Number parsing also lost information silently: 0012 read as 12.
  • One field reader: fieldText takes a string, or an element object whose only keys are attributes and #text (an attribute-only element is empty, like <loc></loc>). Anything else is not one text value: a child element, including a raw < the parser reads as a tag, or the field repeated within one entry. The text around a child element is never used: fast-xml-parser keeps it under #text, and reading it would crawl https://example.com/p?title= for <loc>https://example.com/p?title=<em>Hi</em></loc>. Nothing in the per-entry path can throw any more.
  • One bad entry costs only itself: an entry whose <loc> is not one text value is skipped, and the sitemap records one error for all of them: N <url> entries skipped: <loc> is not a single text value (1 <url> entry skipped: ... for one; <sitemap> for index children). A <lastmod>, <changefreq> or <priority> like that is dropped, its URL kept, and counted once per field: N <lastmod> values ignored: not a single text value. An index child's <lastmod> is not stored but is read the same way, so a raw < in it is reported. Empty <url/> entries and entries with an empty or missing <loc> are skipped silently, as before.
  • What can newly fail: every case that now records one of these errors threw a Parse error on main, except <priority>: main ran parseFloat on whatever it got, so a priority holding markup was silently dropped and a repeated one read its first value. Both now record the priority error. A raw < that swallows the entries after it can only be flagged, not undone: the parser has already folded them into the bad field.
  • Fixture moved: sitemap-guessed-html.test.ts used the bare-year lastmod as its "broken sitemap root" fixture (from fix(crawler): read gzip sitemaps within 50 MB, a guessed path that answers HTML is no sitemap (#662, #670) #686). It now uses a body cut off mid-tag, which the XML parser itself rejects, for the same three prologue variants.
  • Not changed: apps/cli/src/crawl/sitemaps.ts is an older copy of this parser with the same crash, but nothing in apps/cli/src imports it (only tests do). Its removal is now part of CLI: delete the unreferenced external link checker and sitemap parser copies, and point their tests at the shared packages #756.

Follow-ups filed from the review: #758 (the lastmod rules read 2024 as 2024-01-01 and warn on most pages), #759 (a namespace-prefixed <ns0:urlset> root is Unknown sitemap format), #760 (the parser never checks well-formedness, so a mismatched closing tag passes).

Acceptance criteria

  • A urlset whose entries use <lastmod>2024</lastmod> parses with no errors, and each URL keeps lastmod as the string 2024.
  • One malformed entry no longer discards the other URLs in the file. (Markup, a raw < or a repeated <loc> skips that entry only; the same in <lastmod> drops that field only; the same for index children. A text/html-served sitemap with a skipped entry stays a sitemap and keeps its URLs.)
  • A test covers a bare-year lastmod next to a full datetime one. (packages/crawler/tests/sitemap-field-text-687.test.ts)

Verification

  • bun test tests/sitemap-field-text-687.test.ts tests/sitemap-guessed-html.test.ts in packages/crawler: 27 pass. Against main's parser 6 of the first 7 new tests fail.
  • The other crawler sitemap tests (sitemap-entity-expansion, sitemap-gate, sitemap-gzip, sitemap-news-namespace, sitemap-xml-escapes, sitemap-news-column, sitemaps-column-collision): 43 pass.
  • Rules: sitemap-valid, sitemap-lastmod-drift, sitemap-lastmod-churn, sitemap-caps, sitemap-coverage: 71 pass. Engine: streaming-rules-canonical-golden, cloaking-probe: pass, no re-pin.
  • tsgo --noEmit in packages/crawler: clean. oxlint clean on the changed files. The new test file is oxfmt-clean; sitemaps.ts and sitemap-guessed-html.test.ts already had oxfmt drift on main, left as is.
  • docs/: tangly check --strict passes. docs/rules/crawl/sitemap-valid.mdx lists both new errors, says field values are read as text, and the fix advice names the skipped entries.

Agent skill

No change needed: the skill does not describe sitemap parsing.

nc9 added 2 commits October 14, 2026 21:30
…itemap #687

fast-xml-parser's default value parsing turned <lastmod>2024</lastmod>, a
valid W3C Datetime, into the number 2024, and parseSitemap's .trim() threw,
so crawl/sitemap-valid reported the file as a parse error and read none of
its URLs.

The parser now keeps every value as text (parseTagValue: false), and each
field is read through one helper that accepts a string or an element's
#text and nothing else. A field that is not one text value is dropped; an
entry whose <loc> is not one text value is skipped and counted in a single
error per sitemap, and the other entries are still read. Same for
sitemap index children.

sitemap-guessed-html used the bare-year lastmod as its broken-sitemap
fixture; it now uses a body cut off mid-tag.

Signed-off-by: Nik Cubrilovic <[email protected]>
…ount bad optional fields #687

fieldText took #text from any element object, and fast-xml-parser also
fills #text for mixed content: <loc>https://example.com/p?title=<em>Hi</em></loc>
read as https://example.com/p?title= with no error, where main reported a
parse error. An object now yields its text only when every other key is an
attribute; an attribute-only element is empty, like <loc></loc>.

A <lastmod>, <changefreq> or <priority> that is not one text value is still
dropped with its URL kept, and is now counted in one error per field
("N <lastmod> values ignored: not a single text value"), so a raw < that
swallows later entries no longer passes as valid.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/sitemap-bare-year-lastmod-687 branch from 85303d5 to 6f9dca5 Compare October 14, 2026 10:30
@nc9
nc9 marked this pull request as ready for review October 14, 2026 10:35
@claude

claude Bot commented Oct 14, 2026

Copy link
Copy Markdown

Reviewed the diff (sitemaps.ts, tests, docs, changelog). I found nothing that should block the merge. I did not run the test suite.

  • (nit) packages/crawler/src/sitemaps.ts priority: Number.parseFloat still accepts trailing junk, so 0.5abc reads as 0.5. This was already the case before the PR. It is also not range-checked against 0.0–1.0. Neither is a regression.
  • (nit) fieldText returns "" for an attribute-only element, and read() then returns "" rather than undefined. For lastmod and changefreq that gives lastmod: "" instead of an absent value. Downstream code that checks lastmod !== undefined would see an empty string. Normalising empty to undefined would be safer.
  • (nit) In a sitemap index, lastmod is read only so that a raw < gets reported. The comment explains this, so it is fine as written.

What looks good: parseTagValue: false fixes the bare-year <lastmod>2024</lastmod> crash at the cause. Non-text fields are dropped and counted instead of failing the whole file. Text around markup inside a <loc> is never used as the URL. The tests cover the bare year, attributes, nested markup, a duplicate <loc>, a raw <, an index, and the text/html content-type case. Docs and changelog are updated.

@nc9
nc9 merged commit 9c55908 into main Oct 14, 2026
16 checks passed
@nc9
nc9 deleted the fix/sitemap-bare-year-lastmod-687 branch October 14, 2026 11:05
nc9 added a commit that referenced this pull request Oct 14, 2026
…month as that whole period #758

The W3C Datetime format allows `2024` and `2024-09`, which name a whole year
or month. Both rules read them as the first instant (`new Date("2024")` is
2024-01-01T00:00Z), so a year-stamped sitemap looked months behind every
page dated later that year, and churn reported a day nobody wrote. #757
made such sitemaps parse, which exposed it.

A shared w3cDatePeriod turns a lastmod into {start, end, precision}.
Drift treats a page date inside the period as agreeing and measures one
outside it from the nearer end. Churn leaves year and month values out of
its day sample (counted as coarseLastmods / coarseLastmodsExcluded), with a
skip message that says why when they are most of the sample.

Signed-off-by: Nik Cubrilovic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crawl/sitemap-valid: a bare-year <lastmod> fails the whole sitemap with a parse error

1 participant