Skip to content

gh-153404: Silently ignore non-decimal digits in robots.txt Crawl-delay and Request-rate#153405

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:robotparser-isdigit-decimal
Open

gh-153404: Silently ignore non-decimal digits in robots.txt Crawl-delay and Request-rate#153405
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:robotparser-isdigit-decimal

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

str.isdigit() returns True for non-decimal Unicode digits such as U+00B2 SUPERSCRIPT TWO, which int() then rejects with ValueError. In RobotFileParser.parse() this raised a raw ValueError that aborted parsing of the entire robots.txt file, even though every other malformed directive is silently ignored (Allow and Disallow already do try/except ValueError: pass, and invalid Crawl-delay: pears / Request-rate: 9/banana values are already dropped, with existing tests).

The Crawl-delay and Request-rate guards now use str.isdecimal(), the predicate for the decimal digits int() accepts, so a value written with non-decimal digits is ignored instead of raising.

Scope note: a control character that str.strip() removes but int() rejects (for example a byte in U+001C..U+001F inside a Request-rate token) still raises, because the Request-rate branch converts the unstripped token. That is a separate, pre-existing divergence, left out of this single-purpose change.

…wl-delay and Request-rate

str.isdigit() returns True for non-decimal Unicode digits such as
U+00B2 SUPERSCRIPT TWO, which int() then rejects with ValueError. In
RobotFileParser.parse() this raised a raw ValueError that aborted parsing
of the entire robots.txt file, unlike every other malformed directive
which is silently ignored. Guard the Crawl-delay and Request-rate
conversions with str.isdecimal() so a value written with non-decimal
digits is ignored instead of raising.
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