Skip to content
Merged
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
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.19.2
6 changes: 5 additions & 1 deletion src/http_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace {
// - what are the constraints on LITERAL and IDENT?
// - what is the character set for the grammar?
//
// Template = "/" Segments [ Verb ] ;
// Template = "/" | "/" Segments [ Verb ] ;
// Segments = Segment { "/" Segment } ;
// Segment = "*" | "**" | LITERAL | Variable ;
// Variable = "{" FieldPath [ "=" Segments ] "}" ;
Expand Down Expand Up @@ -368,6 +368,10 @@ const char HttpTemplate::kWildCardPathPartKey[] = "*";
const char HttpTemplate::kWildCardPathKey[] = "**";

std::unique_ptr<HttpTemplate> HttpTemplate::Parse(const std::string &ht) {
if (ht == "/") {
return std::unique_ptr<HttpTemplate>(new HttpTemplate({}, {}, {}));
}

Parser p(ht);
if (!p.Parse() || !p.ValidateParts()) {
return nullptr;
Expand Down
19 changes: 17 additions & 2 deletions test/http_template_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,22 @@ TEST(HttpTemplate, ParseTest2) {
ASSERT_EQ(Variables({}), ht->Variables());
}

TEST(HttpTemplate, ParseTest3) {
TEST(HttpTemplate, ParseTest3a) {
auto ht = HttpTemplate::Parse("/**");
ASSERT_NE(nullptr, ht);
ASSERT_EQ(Segments({"**"}), ht->segments());
ASSERT_EQ("", ht->verb());
ASSERT_EQ(Variables(), ht->Variables());
}

TEST(HttpTemplate, ParseTest3b) {
auto ht = HttpTemplate::Parse("/*");
ASSERT_NE(nullptr, ht);
ASSERT_EQ(Segments({"*"}), ht->segments());
ASSERT_EQ("", ht->verb());
ASSERT_EQ(Variables(), ht->Variables());
}

TEST(HttpTemplate, ParseTest4a) {
auto ht = HttpTemplate::Parse("/a:foo");
ASSERT_NE(nullptr, ht);
Expand Down Expand Up @@ -426,9 +434,16 @@ TEST(HttpTemplate, VariableAndCustomVerbTests) {
ht->Variables());
}

TEST(HttpTemplate, RootPATH) {
auto ht = HttpTemplate::Parse("/");
ASSERT_NE(nullptr, ht);
ASSERT_EQ(Segments({}), ht->segments());
ASSERT_EQ("", ht->verb());
ASSERT_EQ(Variables(), ht->Variables());
}

TEST(HttpTemplate, ErrorTests) {
ASSERT_EQ(nullptr, HttpTemplate::Parse(""));
ASSERT_EQ(nullptr, HttpTemplate::Parse("/"));
ASSERT_EQ(nullptr, HttpTemplate::Parse("//"));
ASSERT_EQ(nullptr, HttpTemplate::Parse("/{}"));
ASSERT_EQ(nullptr, HttpTemplate::Parse("/a/"));
Expand Down
2 changes: 2 additions & 0 deletions test/path_matcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ TEST_F(PathMatcherTest, WildCardMatches) {
MethodInfo* c_d__ = AddGetPath("/c/*/d/**");
MethodInfo* c_de = AddGetPath("/c/*/d/e");
MethodInfo* cfde = AddGetPath("/c/f/d/e");
MethodInfo* root = AddGetPath("/");
Build();

EXPECT_NE(nullptr, a__);
Expand All @@ -209,6 +210,7 @@ TEST_F(PathMatcherTest, WildCardMatches) {
EXPECT_EQ(LookupNoBindings("GET", "/a/b"), a__);
EXPECT_EQ(LookupNoBindings("GET", "/a/b/c"), a__);
EXPECT_EQ(LookupNoBindings("GET", "/b/c"), b_);
EXPECT_EQ(LookupNoBindings("GET", "/"), root);

EXPECT_EQ(LookupNoBindings("GET", "b/c/d"), nullptr);
EXPECT_EQ(LookupNoBindings("GET", "/c/u/d/v"), c_d__);
Expand Down
18 changes: 18 additions & 0 deletions test/path_matcher_utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,21 @@ TEST_F(PathMatcherUtilityTest, RegisterAdditionalBindings) {
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
&method2_));
}

TEST_F(PathMatcherUtilityTest, RegisterRootPath) {
HttpRule http_rule;
http_rule.set_get("/");
http_rule.set_body("body");
EXPECT_CALL(pmb,
Register(Eq("GET"), Eq("/"), Eq("body"),
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
.WillOnce(Return(true));
ASSERT_TRUE(
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
EXPECT_CALL(
pmb, Register(Eq("GET"), Eq("/"), Eq("body"),
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
.WillOnce(Return(false));
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
&method2_));
}