Bug description:
urllib.robotparser.RobotFileParser.can_fetch is documented to return a bool,
but it passes url straight to urllib.parse._urlsplit, so a malformed URL
(an unterminated IPv6 authority) raises a bare ValueError instead of a
result:
import urllib.robotparser
p = urllib.robotparser.RobotFileParser()
p.parse(["User-agent: *", "Disallow: /"])
p.can_fetch("*", "http://[::1") # ValueError: Invalid IPv6 URL
The url argument is crawl-frontier-controlled (it comes from parsed pages).
Proposed behavior: a URL that cannot be parsed matches no rule, so can_fetch
returns True (RFC 9309 default that access is not restricted when no rule
applies), rather than raising or being conservatively False.
This is a sibling of #153404 (robotparser raising ValueError on a non-decimal
digit in Crawl-delay / Request-rate); the sink there is the robots.txt
content, here it is the url argument.
CPython versions tested on:
3.13, 3.14, 3.15
Operating systems tested on:
macOS
Linked PRs
Bug description:
urllib.robotparser.RobotFileParser.can_fetchis documented to return a bool,but it passes
urlstraight tourllib.parse._urlsplit, so a malformed URL(an unterminated IPv6 authority) raises a bare
ValueErrorinstead of aresult:
The
urlargument is crawl-frontier-controlled (it comes from parsed pages).Proposed behavior: a URL that cannot be parsed matches no rule, so
can_fetchreturns
True(RFC 9309 default that access is not restricted when no ruleapplies), rather than raising or being conservatively
False.This is a sibling of #153404 (robotparser raising
ValueErroron a non-decimaldigit in
Crawl-delay/Request-rate); the sink there is the robots.txtcontent, here it is the
urlargument.CPython versions tested on:
3.13, 3.14, 3.15
Operating systems tested on:
macOS
Linked PRs