Skip to content

gh-153795: Stop urllib.robotparser.can_fetch crashing on a malformed URL#153796

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:robotparser-canfetch-malformed-url
Open

gh-153795: Stop urllib.robotparser.can_fetch crashing on a malformed URL#153796
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:robotparser-canfetch-malformed-url

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

RobotFileParser.can_fetch() is documented to return a bool, but it passed the url straight to urllib.parse._urlsplit(), so a malformed url (an unterminated IPv6 authority) raised a bare ValueError. Treat a url that cannot be parsed as matching no rule and return True, matching RFC 9309's default that access is not restricted when no rule applies. The try wraps only the _urlsplit() call. Sibling of #153404 (same crash class from the robots.txt content side).

…ormed URL

RobotFileParser.can_fetch() is documented to return a bool, but it passed the
url straight to urllib.parse._urlsplit(), so a malformed url such as an
unterminated IPv6 authority raised a bare ValueError out of can_fetch(). Treat
a url that cannot be parsed as matching no rule and return True, matching RFC
9309's default that access is not restricted when no rule applies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant