gh-153404: Silently ignore non-decimal digits in robots.txt Crawl-delay and Request-rate#153405
Open
tonghuaroot wants to merge 1 commit into
Open
gh-153404: Silently ignore non-decimal digits in robots.txt Crawl-delay and Request-rate#153405tonghuaroot wants to merge 1 commit into
tonghuaroot wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
str.isdigit()returns True for non-decimal Unicode digits such asU+00B2 SUPERSCRIPT TWO, whichint()then rejects withValueError. InRobotFileParser.parse()this raised a rawValueErrorthat aborted parsing of the entirerobots.txtfile, even though every other malformed directive is silently ignored (AllowandDisallowalready dotry/except ValueError: pass, and invalidCrawl-delay: pears/Request-rate: 9/bananavalues are already dropped, with existing tests).The
Crawl-delayandRequest-rateguards now usestr.isdecimal(), the predicate for the decimal digitsint()accepts, so a value written with non-decimal digits is ignored instead of raising.Scope note: a control character that
str.strip()removes butint()rejects (for example a byte inU+001C..U+001Finside aRequest-ratetoken) still raises, because theRequest-ratebranch converts the unstripped token. That is a separate, pre-existing divergence, left out of this single-purpose change.