-
Notifications
You must be signed in to change notification settings - Fork 5
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
Handle leading wildcard in directive path #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,3 +319,39 @@ TEST(RobotsTest, NeverExternalAllowed) | |
Rep::Robots robot("", "http://a.com/robots.txt"); | ||
EXPECT_FALSE(robot.allowed("http://b.com/", "one")); | ||
} | ||
|
||
TEST(RobotsTest, LeadingWildcardAllow) | ||
{ | ||
std::string content = | ||
"User-agent: meow\n" | ||
"Disallow: /\n" | ||
"Allow: ****/cats\n" | ||
"Allow: */kangaroos\n"; | ||
Rep::Robots robot(content); | ||
|
||
EXPECT_FALSE(robot.allowed("/kangaroo/zebra/cat/page.html", "meow")); | ||
EXPECT_TRUE(robot.allowed("/cats.html", "meow")); | ||
EXPECT_TRUE(robot.allowed("/cats/page.html", "meow")); | ||
EXPECT_TRUE(robot.allowed("/get/more/cats/page.html", "meow")); | ||
EXPECT_TRUE(robot.allowed("/kangaroos/page.html", "meow")); | ||
EXPECT_TRUE(robot.allowed("/heaps/of/kangaroos/page.html", "meow")); | ||
EXPECT_TRUE(robot.allowed("/kangaroosandkoalas/page.html", "meow")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like a case with neither There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first line has neither
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to add a specific test if you have one in mind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. D'oh! Never mind. |
||
} | ||
|
||
TEST(RobotsTest, LeadingWildcardDisallow) | ||
{ | ||
std::string content = | ||
"User-agent: meow\n" | ||
"Allow: /\n" | ||
"Disallow: ****/cats\n" | ||
"Disallow: */kangaroos\n"; | ||
Rep::Robots robot(content); | ||
|
||
EXPECT_TRUE(robot.allowed("/kangaroo/zebra/cat/page.html", "meow")); | ||
EXPECT_FALSE(robot.allowed("/cats.html", "meow")); | ||
EXPECT_FALSE(robot.allowed("/cats/page.html", "meow")); | ||
EXPECT_FALSE(robot.allowed("/get/more/cats/page.html", "meow")); | ||
EXPECT_FALSE(robot.allowed("/kangaroos/page.html", "meow")); | ||
EXPECT_FALSE(robot.allowed("/heaps/of/kangaroos/page.html", "meow")); | ||
EXPECT_FALSE(robot.allowed("/kangaroosandkoalas/page.html", "meow")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean for there to be an
else
here? As this stands, you're pushing both the trimmed and untrimmed versions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is the intent. There is an explanation in my PR comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh again!