fix(sitemap): let Sitemap.from_xml_string opt into enqueue host filtering - #2162
Open
aryansk wants to merge 1 commit into
Open
fix(sitemap): let Sitemap.from_xml_string opt into enqueue host filtering#2162aryansk wants to merge 1 commit into
aryansk wants to merge 1 commit into
Conversation
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>
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.
Summary
Sitemap.from_xml_stringonly acceptedcontentand hardcodedSitemapSource(type='raw', content=content)with nourl, so host filtering — conditional onsource.get('url')— was silently skipped for raw sitemap XML. Even when the caller knew where the content came from, the defaultsame-hostnameenqueue strategy never applied.This adds optional
sitemap_urlandparse_sitemap_optionsparameters, forwarded asSitemapSource(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.py—from_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 whensitemap_urlis given, andenqueue_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 --checkclean on changed files.🤖 Generated with Codebuff