Skip to content
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

Merged
merged 3 commits into from
Jun 11, 2019
Merged

Conversation

tammybailey
Copy link
Contributor

This code considers one or more leading wildcard characters (*) as a special case in the Agent code. We push an additional directive to the directives_ vector in the Agent::Allow and Agent::Disallow functions which is the result of evaluating the input query stripped of leading '*'s. That is, we evaluate e.g. Disallow: */test as Disallow: /test and Disallow: /*/test.

Issue report here: #34

@tammybailey tammybailey requested a review from lindseyreno June 10, 2019 23:32
@tammybailey
Copy link
Contributor Author

@dlecocq would you review please and thank you?

@tammybailey tammybailey requested a review from sistawendy June 10, 2019 23:36
src/agent.cpp Outdated
@@ -1,7 +1,6 @@
#include <algorithm>
#include <iomanip>
#include <sstream>

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?

Copy link
Contributor Author

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)
{

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?

Copy link
Contributor Author

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"));

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.

Copy link
Contributor Author

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"));

Copy link
Contributor Author

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?

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"));

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));
}

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.

Copy link
Contributor Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh again!

Copy link

@sistawendy sistawendy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍤

@tammybailey tammybailey merged commit 3da0bbb into master Jun 11, 2019
@tammybailey tammybailey deleted the tammy-wildcard branch June 11, 2019 17:30
@dlecocq
Copy link

dlecocq commented Jun 11, 2019

I know it's already merged, it LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants