Skip to content

fix(sitemap): parse, normalize and deduplicate urlset <loc> entries - #332

Closed
tobocop2 wants to merge 2 commits into
fix/sitemap-parse-child-locfrom
fix/sitemap-urlset-loc-normalized
Closed

tobocop2 wants to merge 2 commits into
fix/sitemap-parse-child-locfrom
fix/sitemap-urlset-loc-normalized

Conversation

@tobocop2

@tobocop2 tobocop2 commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Stacked on #303.

Problem

map() returned each sitemap <loc> as raw text. https://example.com/a and HTTPS://example.com:443/a came back as two entries. A relative <loc> came back as a bare path, and a <loc> that is not an address came back as text.

Normalized entries

Each <loc> is now resolved against the sitemap's own URL with the parser that sitemap-index children use, and it is returned in its normalized form. An entry on another host stays on that host.

Unparseable entries

A <loc> that does not parse is dropped. The log records its length, never its value.

Duplicates

An address is returned once per map() call, also when several sitemaps list it. A duplicate does not count toward map_limit.

Changed filtering

A relative <loc> now resolves to an address, so exclude_paths applies to it. map_search now matches the normalized address, so a search for a raw spelling (a default port, or non-ASCII text in the path or host) no longer matches; #338 tracks matching non-ASCII terms.

Local verification

cargo fmt --check, workspace clippy with --all-features --all-targets -D warnings, cargo test -p crawlberg --all-features (851 lib tests pass) and the wasm32 check all pass.

Closes #323

map() returned each urlset <loc> as the trimmed raw text. Two spellings
of one page (an upper-case scheme or host, a default port, an embedded
tab or newline) came back as two entries, a relative <loc> came back as
a bare path, and a <loc> that is not an address came back as text.

Every urlset consumer (the leaf of a sitemap walk and a urlset or gzip
fetched directly) now goes through one collector. It resolves each <loc>
against the sitemap's own URL with the resolver sitemap-index children
use, without their host rewrite, so an entry on another host stays on
that host. A <loc> that does not parse is dropped and logged by length;
the sitemap URL is logged redacted when it parses and by length when it
does not, through the log helper the index-child path now shares.

Entries are deduplicated on the parsed address across every document
of one map() call: the walk context, created once per call, holds the
set behind a mutex that is only locked in synchronous code. A duplicate
is dropped before it counts toward map_limit. A relative <loc> now
resolves to an address, so exclude_paths applies to it, and map_search
matches the normalized address rather than the raw spelling.

Closes #323
@Goldziher
Goldziher force-pushed the fix/sitemap-parse-child-loc branch from d3064ed to 00f050c Compare September 27, 2026 08:53
@Goldziher
Goldziher force-pushed the fix/sitemap-urlset-loc-normalized branch from d6095f6 to 1ab54b8 Compare September 27, 2026 08:53
@tobocop2

Copy link
Copy Markdown
Member Author

Landed through #494 (squash 2051cfa on integration/0927), which carries this change with the rest of the sitemap stack and closes its issue.

@tobocop2 tobocop2 closed this Sep 29, 2026
@tobocop2
tobocop2 removed this pull request from stack #460 September 29, 2026 03:58
@Goldziher
Goldziher deleted the fix/sitemap-urlset-loc-normalized branch October 10, 2026 07:50
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.

fix(sitemap): sitemap page entries are used as raw text and never deduplicated

1 participant