fix(robots): Disallow /*? should only match URLs with query strings - #2226
Open
Zsanz3 wants to merge 3 commits into
Open
fix(robots): Disallow /*? should only match URLs with query strings#2226Zsanz3 wants to merge 3 commits into
Zsanz3 wants to merge 3 commits into
Conversation
urllib.robotparser normalizes rule paths with urlparse/urlunparse, which drops an empty query. Combined with the wildcard patch, Disallow: /*? collapsed to Disallow: /* and blocked the entire site. Preserve the trailing ? on RuleLine paths and require a query marker before treating those rules as a match. Fixes unclecode#2225 Co-authored-by: Zsanz3 <Zsanz3@users.noreply.github.com>
Co-authored-by: Zsanz3 <Zsanz3@users.noreply.github.com>
RobotsParser.can_fetch appended '=' to the raw URL, which turned page?#frag into page?#frag= and could treat a '?' that lives only in the fragment as a query. Rebuild via urlunparse when '?' is in the pre-# part so the query becomes '=' and the fragment is kept. Co-authored-by: Zsanz3 <Zsanz3@users.noreply.github.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.
Fixes #2225.
Summary
urllib.robotparser.RuleLinenormalizes rule paths withurlparse/urlunparse, which drops an empty query. Combined with crawl4ai's wildcard monkey-patch, a common ecommerce rule:was collapsed to
Disallow: /*. After the*/%2Aregex rewrite that became^/.*, so the entire site was disallowed — including URLs with no query string.The intent of
/*?is only to block URLs that actually carry a query string (for example/page?q=1or/?s=search), not/pageor/.Fix
?onRuleLinepaths as%3Fafter stdlib init.patched_applies_to, refuse to match a query-marker rule against a filename that has no query marker.RobotsParser.can_fetch, when the URL has?in the pre-fragment part but an empty query after parse, rebuild viaurlunparsewithquery=\"=\"sopage?#fragstayspage?=#frag(not fragment corruption). BareRobotFileParser.can_fetchstill allowspage?; this rewrite isRobotsParser-only.Tests
tests/general/test_robot_parser.py: non-query URLs allowed;?q=,?s=,page?, andpage?#fragblocked underDisallow: /*?.