Skip to content

fix(sitemaps): allow Sitemap.from_xml_string to opt into enqueue host filtering - #2162

Merged
vdusek merged 3 commits into
apify:masterfrom
aryansk:fix/2118-sitemap-from-xml-host-filter
Aug 18, 2026
Merged

fix(sitemaps): allow Sitemap.from_xml_string to opt into enqueue host filtering#2162
vdusek merged 3 commits into
apify:masterfrom
aryansk:fix/2118-sitemap-from-xml-host-filter

Conversation

@aryansk

@aryansk aryansk commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Sitemap.from_xml_string only accepted content and hardcoded SitemapSource(type='raw', content=content) with no url, so host filtering — conditional on source.get('url') — was silently skipped for raw sitemap XML. Even when the caller knew where the content came from, the default same-hostname enqueue strategy never applied.

This adds optional sitemap_url and parse_sitemap_options parameters, forwarded as SitemapSource(type='raw', content=content, url=sitemap_url) so raw content participates in the exact same host-filtering and parse options as URL-loaded sitemaps.

Closes #2118

Changes

  • src/crawlee/_utils/sitemap.pyfrom_xml_string(content, *, sitemap_url=None, parse_sitemap_options=None).
  • tests/unit/_utils/test_sitemap.py — three regression tests: same-host URLs kept with the default strategy, cross-host URLs filtered when sitemap_url is given, and enqueue_strategy='all' disabling the filter for raw string sitemaps. All three fail on the pre-fix code.

Validation

  • tests/unit/_utils/test_sitemap.py: 67 passed (3 new).
  • tests/unit/_utils/: 297 passed, 6 skipped (Linux-only).
  • tests/unit/request_loaders/test_sitemap_request_loader.py: 46 passed.
  • ruff check + ruff format --check clean on changed files.

🤖 Generated with Codebuff

Sitemap.from_xml_string hardcoded a raw SitemapSource with no url, so
host filtering (default `same-hostname`) was silently skipped whenever
raw XML was parsed — even when the caller knew where the sitemap came
from. Accept optional `sitemap_url` and `parse_sitemap_options` and
forward them so the source carries an origin and the same enqueue
strategy rules apply as for URL-loaded sitemaps (gh apify#2118).

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@vdusek vdusek changed the title fix(sitemap): let Sitemap.from_xml_string opt into enqueue host filtering fix(sitemaps): allow Sitemap.from_xml_string to opt into enqueue host filtering Aug 18, 2026

@vdusek vdusek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vdusek
vdusek merged commit a3c20c1 into apify:master Aug 18, 2026
34 checks passed
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.

Sitemap.from_xml_string cannot opt into enqueue host filtering

4 participants