Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Allow robots.txt with no useragent
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Sep 12, 2011
1 parent 411cbb7 commit 1f55490
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/robotstxt/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,20 @@ def parse(body)

when "Disallow"

if @rules.any?
parser_mode = :rules
if value == ""
@rules.last[1] << ["*", true]
else
@rules.last[1] << [value, false]
end
parser_mode = :rules
@rules << ["*", []] if @rules.empty?

if value == ""
@rules.last[1] << ["*", true]
else
@rules.last[1] << [value, false]
end

when "Allow"

if @rules.any?
parser_mode = :rules
@rules.last[1] << [value, true]
end
parser_mode = :rules
@rules << ["*", []] if @rules.empty?
@rules.last[1] << [value, true]

when "Sitemap"
@sitemaps << value
Expand Down
8 changes: 8 additions & 0 deletions test/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ def test_useragents
assert false == Robotstxt::Parser.new("Bing", robotstxt).allowed?("/hello")
end

def test_missing_useragent
robotstxt = <<-ROBOTS
Disallow: /index
ROBOTS
assert true === Robotstxt::Parser.new("Google", robotstxt).allowed?("/hello")
assert false === Robotstxt::Parser.new("Google", robotstxt).allowed?("/index/wold")
end

end

0 comments on commit 1f55490

Please sign in to comment.