nghttpx: Fix broken trailing slash handling
nghttpx allows a pattern with trailing slash to match a request path without it. Previously, under certain pattern registration, this does not work.
This commit is contained in:
parent
302abf1b46
commit
f3f40840b3
|
@ -220,9 +220,16 @@ const RNode *match_partial(bool *pattern_is_wildcard, const RNode *node,
|
|||
return node;
|
||||
}
|
||||
|
||||
// The last '/' handling, see below.
|
||||
node = find_next_node(node, '/');
|
||||
if (node != nullptr && node->index != -1 && node->len == 1) {
|
||||
return node;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The last '/' handling, see below.
|
||||
if (node->index != -1 && offset + n + 1 == node->len &&
|
||||
node->s[node->len - 1] == '/') {
|
||||
return node;
|
||||
|
@ -265,6 +272,13 @@ const RNode *match_partial(bool *pattern_is_wildcard, const RNode *node,
|
|||
return node;
|
||||
}
|
||||
|
||||
// The last '/' handling, see below.
|
||||
node = find_next_node(node, '/');
|
||||
if (node != nullptr && node->index != -1 && node->len == 1) {
|
||||
*pattern_is_wildcard = false;
|
||||
return node;
|
||||
}
|
||||
|
||||
return found_node;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,9 @@ void test_shrpx_router_match(void) {
|
|||
{StringRef::from_lit("www.nghttp2.org/alpha/"), 4},
|
||||
{StringRef::from_lit("/alpha"), 5},
|
||||
{StringRef::from_lit("example.com/alpha/"), 6},
|
||||
{StringRef::from_lit("nghttp2.org/alpha/bravo2/"), 7},
|
||||
{StringRef::from_lit("www2.nghttp2.org/alpha/"), 8},
|
||||
{StringRef::from_lit("www2.nghttp2.org/alpha2/"), 9},
|
||||
};
|
||||
|
||||
Router router;
|
||||
|
@ -84,6 +87,13 @@ void test_shrpx_router_match(void) {
|
|||
idx = router.match(StringRef::from_lit("nghttp2.org"),
|
||||
StringRef::from_lit("/alpha/bravo"));
|
||||
|
||||
CU_ASSERT(3 == idx);
|
||||
|
||||
idx = router.match(StringRef::from_lit("www2.nghttp2.org"),
|
||||
StringRef::from_lit("/alpha"));
|
||||
|
||||
CU_ASSERT(8 == idx);
|
||||
|
||||
idx = router.match(StringRef{}, StringRef::from_lit("/alpha"));
|
||||
|
||||
CU_ASSERT(5 == idx);
|
||||
|
|
Loading…
Reference in New Issue