-
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
Conversation
@dlecocq would you review please and thank you? |
src/agent.cpp
Outdated
@@ -1,7 +1,6 @@ | |||
#include <algorithm> | |||
#include <iomanip> | |||
#include <sstream> | |||
|
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.
Was this line here to separate system includes from the rest?
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.
No idea? I probably added or removed it by accident when adding iostream
for debugging.
src/agent.cpp
Outdated
} | ||
|
||
namespace Rep | ||
{ | ||
Agent& Agent::allow(const std::string& query) | ||
{ | ||
|
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.
Why a blank line here?
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.
I have no explanation for this blank line.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a case with neither cats
nor kangaroos
.
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.
The first line has neither cats
nor kangaroos
:
EXPECT_FALSE(robot.allowed("/kangaroo/zebra/cat/page.html", "meow"));
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh! Never mind.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
{ | ||
Url::Url trimmed(trim_front(query, '*')); | ||
directives_.push_back(Directive(escape_url(trimmed), false)); | ||
} |
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!
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.
🍤
I know it's already merged, it LGTM! |
This code considers one or more leading wildcard characters (
*
) as a special case in theAgent
code. We push an additional directive to thedirectives_
vector in theAgent::Allow
andAgent::Disallow
functions which is the result of evaluating the input query stripped of leading '*'s. That is, we evaluate e.g.Disallow: */test
asDisallow: /test
andDisallow: /*/test
.Issue report here: #34