Repository navigation
fix(crawler): a bare-year sitemap lastmod no longer fails the whole sitemap #687 - #757
Merged
Merged
Conversation
…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
force-pushed
the
fix/sitemap-bare-year-lastmod-687
branch
from
October 14, 2026 10:30
85303d5 to
6f9dca5
Compare
… singular field error #687 Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
marked this pull request as ready for review
October 14, 2026 10:35
|
Reviewed the diff (
What looks good: |
This was referenced Oct 14, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 number2024,.trim()threw, andcrawl/sitemap-validreported the whole file as an error startingParse error: entry.lastmod?.trim is not a function, with none of its URLs read.parseTagValue: false, so every value is the text the sitemap wrote (2024stays"2024",<priority>0.80</priority>still becomes0.8through the existingparseFloat). Number parsing also lost information silently:0012read as12.fieldTexttakes 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 crawlhttps://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.<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.Parse erroron main, except<priority>: main ranparseFloaton 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.sitemap-guessed-html.test.tsused 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.apps/cli/src/crawl/sitemaps.tsis an older copy of this parser with the same crash, but nothing inapps/cli/srcimports 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
2024as 2024-01-01 and warn on most pages), #759 (a namespace-prefixed<ns0:urlset>root isUnknown sitemap format), #760 (the parser never checks well-formedness, so a mismatched closing tag passes).Acceptance criteria
<lastmod>2024</lastmod>parses with no errors, and each URL keepslastmodas the string2024.<or a repeated<loc>skips that entry only; the same in<lastmod>drops that field only; the same for index children. Atext/html-served sitemap with a skipped entry stays a sitemap and keeps its URLs.)packages/crawler/tests/sitemap-field-text-687.test.ts)Verification
bun test tests/sitemap-field-text-687.test.ts tests/sitemap-guessed-html.test.tsinpackages/crawler: 27 pass. Against main's parser 6 of the first 7 new tests fail.sitemap-entity-expansion,sitemap-gate,sitemap-gzip,sitemap-news-namespace,sitemap-xml-escapes,sitemap-news-column,sitemaps-column-collision): 43 pass.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 --noEmitinpackages/crawler: clean. oxlint clean on the changed files. The new test file is oxfmt-clean;sitemaps.tsandsitemap-guessed-html.test.tsalready had oxfmt drift on main, left as is.docs/:tangly check --strictpasses.docs/rules/crawl/sitemap-valid.mdxlists 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.