Skip to content

fix(robots): Disallow /*? should only match URLs with query strings - #2226

Open
Zsanz3 wants to merge 3 commits into
unclecode:mainfrom
Zsanz3:cursor/fix-robots-query-wildcard-873d
Open

fix(robots): Disallow /*? should only match URLs with query strings#2226
Zsanz3 wants to merge 3 commits into
unclecode:mainfrom
Zsanz3:cursor/fix-robots-query-wildcard-873d

Conversation

@Zsanz3

@Zsanz3 Zsanz3 commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #2225.

Summary

urllib.robotparser.RuleLine normalizes rule paths with urlparse / urlunparse, which drops an empty query. Combined with crawl4ai's wildcard monkey-patch, a common ecommerce rule:

Disallow: /*?

was collapsed to Disallow: /*. After the * / %2A regex 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=1 or /?s=search), not /page or /.

Fix

  • Preserve a trailing empty ? on RuleLine paths as %3F after stdlib init.
  • In patched_applies_to, refuse to match a query-marker rule against a filename that has no query marker.
  • In RobotsParser.can_fetch, when the URL has ? in the pre-fragment part but an empty query after parse, rebuild via urlunparse with query=\"=\" so page?#frag stays page?=#frag (not fragment corruption). Bare RobotFileParser.can_fetch still allows page?; this rewrite is RobotsParser-only.

Tests

tests/general/test_robot_parser.py: non-query URLs allowed; ?q=, ?s=, page?, and page?#frag blocked under Disallow: /*?.

Zsanz3 and others added 3 commits September 2, 2026 01:54
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>
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.

[Bug]: Disallow: /*? in robots.txt blocks the whole website.

1 participant