fix: preventing disallow: /*? from blocking the whole website. - #2229
Conversation
|
Verified locally and this looks good to merge. What I checked
Two small nits (non-blocking)
Not caused by this PR, noting for a future follow-up
Thanks for the fix @Nalhin |
|
Great, thanks @SohamKukreti! Can we get this landed? |
|
@SohamKukreti I've addressed the nits |
|
Merged — thanks @Nalhin! The Digging into this turned up a second bug right next to it — the wildcard monkey patch breaks |
* fix(robots): don't patch robotparser on Python 3.14+
The wildcard monkey patch in utils.py overrides RuleLine.applies_to
unconditionally. Python 3.14 rewrote urllib.robotparser with native
wildcard, '$' and RFC 9309 longest-match support, where applies_to
returns the match *length* used to rank competing rules. The patch
returns a bool, so every wildcard rule collapses to the lowest
priority and Allow: overrides stop working:
User-agent: *
Disallow: /
Allow: /public/*.html
denied /public/a.html on 3.14. Gate the patch to Python < 3.14, where
robotparser has no wildcard support and still needs it.
Follow-up to #2229, which fixed the 'Disallow: /*?' half of #2225.
Refs #2225
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(robots): don't rewrite bare-'?' rules on Python 3.14+ either
Review follow-up on the previous commit, which gated the RuleLine
monkey patch but left _preserve_bare_query running on every Python.
On 3.14 that rewrite is not just unnecessary, it is wrong. The stdlib
ranks rules by match length, and '/*?*' matches to end of string, so
it outranks a narrower competing Allow:
User-agent: *
Allow: /*?q=
Disallow: /*?
/search?q=1 is allowed by the stdlib and denied after the rewrite, so
Crawl4AI skipped pages robots.txt permits. Gate the call with the same
sys.version_info < (3, 14) as the patch, and say so in the docstring,
which claimed the two forms were always equivalent.
Also move the RuleLine import inside the branch that uses it and drop
a duplicate 'import re'.
Refs #2225
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
@ntohidi Thanks for getting this landed! |
Summary
Fixes #2225 - disallow: /*? in robots.txt blocks the whole website.
List of files changed and why
Adding logic in robots parser to append "*" after "?" so that urls ending with "?" get parsed correctly by the lib.
How Has This Been Tested?
Unit tests for this specific edge case.
Checklist: