Fix robots.txt parser for stacked user-agent groups (RFC 9309)#6
Open
federicobartoli wants to merge 2 commits intoaddyosmani:mainfrom
Open
Fix robots.txt parser for stacked user-agent groups (RFC 9309)#6federicobartoli wants to merge 2 commits intoaddyosmani:mainfrom
federicobartoli wants to merge 2 commits intoaddyosmani:mainfrom
Conversation
parseRobotsTxt previously overwrote currentAgent on every User-agent line, so robots.txt files that stack multiple user-agents before a shared block of rules (e.g. docs.nvidia.com/robots.txt) attributed those rules only to the last agent in the stack. RFC 9309 §2.1 defines a group as "one or more user-agent lines followed by one or more rules"; the ABNF grammar in §2.2 formalises this with startgroupline repeating before rules. Accumulate agents in currentAgents and reset the group only when a User-agent line follows a rule line.
The robots-txt checker only treated literal `Allow: /` as an explicit allowance. Sites that welcome AI crawlers with more specific rules (e.g. `Allow: /*.llms.txt$`) were still reported as having no explicitly allowed crawlers. Treat any non-empty Allow rule for a known AI crawler as an explicit allowance. Combined with the preceding parser fix, this closes the false positive reported in addyosmani#5. Adds a regression fixture and tests modeled on docs.nvidia.com. Fixes addyosmani#5
4e090e3 to
bddf6cb
Compare
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.
Summary
User-agentlines as a single group per RFC 9309 (§2.1, §2.2) instead of keeping only the last agentAllowrule (not justAllow: /) as an explicit allowance for scoringparseRobotsTxtTest plan
node --test)Fixes #5