Skip to content

Parsing error: user-agent label is case sensitive and collapses user-agent specific settings #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/robots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def initialize(uri, user_agent)
io.each do |line|
next if line =~ /^\s*(#.*|$)/
arr = line.split(":")
key = arr.shift
key = arr.shift.to_s.downcase
value = arr.join(":").strip
value.strip!
case key
when "User-agent"
when "user-agent"
agent = to_regex(value)
when "Allow"
when "allow"
@allows[agent] ||= []
@allows[agent] << to_regex(value)
when "Disallow"
when "disallow"
@disallows[agent] ||= []
@disallows[agent] << to_regex(value)
when "Crawl-delay"
when "crawl-delay"
@delays[agent] = value.to_i
else
@other[key] ||= []
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/mixcase.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *
Disallow: /test
User-Agent: Another
Disallow: /
7 changes: 6 additions & 1 deletion test/test_robots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ def test_site_with_disallowed
end

def test_other_values
sitemap = {"Sitemap" => ["http://www.eventbrite.com/sitemap_index.xml", "http://www.eventbrite.com/sitemap_index.xml"]}
sitemap = {"sitemap" => ["http://www.eventbrite.com/sitemap_index.xml", "http://www.eventbrite.com/sitemap_index.xml"]}
assert_other_equals("eventbrite", sitemap)
end

def test_mix_case_user_agent
assert_allowed("mixcase", "/")
assert_disallowed("mixcase", "/test")
end

def assert_other_equals(name, value)
assert_equal(value, @robots.other_values(uri_for_name(name, "/")))
end
Expand Down