Skip to content
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
11 changes: 10 additions & 1 deletion src/agent.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <algorithm>
#include <sstream>
#include <regex>

#include "url.h"

Expand Down Expand Up @@ -82,6 +83,14 @@ namespace Rep

std::string Agent::escape(const std::string& query)
{
return Url::Url(query).defrag().escape().fullpath();
std::regex escaped_slash ("%2[Ff]");
std::regex escaped_newline ("\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a newline character for this seems like a gross hack rather than a long term solution. I'd really prefer a fix that was cleaner.

std::string result;

result = std::regex_replace(query, escaped_slash, "\n");

std::string url = Url::Url(result).defrag().escape().fullpath();

return std::regex_replace(url, escaped_newline, "%2F");
}
}
9 changes: 9 additions & 0 deletions test/test-robots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ TEST(RobotsTest, HonorsDefaultAgent)
EXPECT_TRUE(robot.allowed("/path", "agent"));
}

TEST(RobotsTest, EscapedSlash)
{
std::string content =
"User-agent: *\n"
"Disallow: /*%2F\n";
Rep::Robots robot(content);
EXPECT_TRUE(robot.allowed("/tmp/", "one"));
}

TEST(RobotsTest, HonorsSpecificAgent)
{
std::string content =
Expand Down