You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
urllib.robotparser raises ValueError for a non-decimal digit in Crawl-delay or Request-rate #153404
urllib.robotparser.RobotFileParser.parse() raises a bare ValueError and aborts parsing of the entire robots.txt file when a Crawl-delay or Request-rate directive has a value written with a non-decimal Unicode digit.
fromurllib.robotparserimportRobotFileParserrp=RobotFileParser()
rp.parse(["User-agent: *", "Crawl-delay: ²"]) # U+00B2 SUPERSCRIPT TWO
Actual:
ValueError: invalid literal for int() with base 10: '²'
Request-rate: ²/5 fails the same way.
Expected: the malformed directive is silently ignored, like every other malformed line in a robots.txt file. Allow and Disallow already do try/except ValueError: pass, and an invalid value such as Crawl-delay: pears or Request-rate: 9/banana is already ignored (there are existing tests for those). One bad value should not abort parsing of the whole file.
Root cause: parse() guards the int() conversion with str.isdigit(), but str.isdigit() returns True for non-decimal Unicode digits (superscripts, subscripts, circled digits, ...) that int() then rejects. str.isdecimal() is the predicate that matches the decimal digits int() accepts.
Activity
gh-153404: Silently ignore non-decimal digits in robots.txt Crawl-del…
[3.13] gh-153404: Silently ignore non-decimal digits in robots.txt Cr…
[3.14] gh-153404: Silently ignore non-decimal digits in robots.txt Cr…
[3.15] gh-153404: Silently ignore non-decimal digits in robots.txt Cr…