summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAxel Duch <axel.duch@nginx.com>2020-07-10 10:28:53 +0100
committerAxel Duch <axel.duch@nginx.com>2020-07-10 10:28:53 +0100
commitb6792b00aebbe08f0fa3a4cb7826075114f717fa (patch)
tree18999d6b265587f82ea958308f3d877bad368354
parent18fbfc3d5027df68b7696afb16323c66f2582100 (diff)
downloadunit-b6792b00aebbe08f0fa3a4cb7826075114f717fa.tar.gz
unit-b6792b00aebbe08f0fa3a4cb7826075114f717fa.tar.bz2
Router: route patterns multi wildcards fix.
Matching 'start' and 'end' position now adjusted to avoid false matching. This is related to #434 issue on Github. Thanks to 洪志道 (Hong Zhi Dao).
Diffstat (limited to '')
-rw-r--r--src/nxt_http_route.c9
-rw-r--r--test/test_routing.py21
2 files changed, 27 insertions, 3 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index 66ab0fcd..6bdf2937 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -2344,6 +2344,7 @@ nxt_http_route_pattern(nxt_http_request_t *r, nxt_http_route_pattern_t *pattern,
pattern_slices = pattern->pattern_slices;
pattern_slice = pattern_slices->elts;
+ end = start + length;
for (i = 0; i < pattern_slices->nelts; i++, pattern_slice++) {
test = pattern_slice->start;
@@ -2359,25 +2360,25 @@ nxt_http_route_pattern(nxt_http_request_t *r, nxt_http_route_pattern_t *pattern,
if (nxt_http_route_memcmp(start, test, test_length,
pattern->case_sensitive))
{
+ start += test_length;
break;
}
return 0;
case NXT_HTTP_ROUTE_PATTERN_END:
- p = start + length - test_length;
+ p = end - test_length;
if (nxt_http_route_memcmp(p, test, test_length,
pattern->case_sensitive))
{
+ end = p;
break;
}
return 0;
case NXT_HTTP_ROUTE_PATTERN_SUBSTRING:
- end = start + length;
-
if (pattern->case_sensitive) {
p = nxt_memstrn(start, end, (char *) test, test_length);
@@ -2388,6 +2389,8 @@ nxt_http_route_pattern(nxt_http_request_t *r, nxt_http_route_pattern_t *pattern,
if (p == NULL) {
return 0;
}
+
+ start = p + test_length;
}
}
diff --git a/test/test_routing.py b/test/test_routing.py
index 8a196e88..269e8efc 100644
--- a/test/test_routing.py
+++ b/test/test_routing.py
@@ -200,6 +200,27 @@ class TestRouting(TestApplicationProto):
self.assertEqual(self.get(url='/blah')['status'], 200, '/blah')
self.assertEqual(self.get(url='/BLAH')['status'], 404, '/BLAH')
+ def test_route_match_wildcards_ordered(self):
+ self.route_match({"uri": "/a*x*y*"})
+
+ self.assertEqual(self.get(url='/axy')['status'], 200, '/axy')
+ self.assertEqual(self.get(url='/ayx')['status'], 404, '/ayx')
+
+ def test_route_match_wildcards_adjust_start(self):
+ self.route_match({"uri": "/bla*bla*"})
+
+ self.assertEqual(self.get(url='/bla_foo')['status'], 404, '/bla_foo')
+
+ def test_route_match_wildcards_adjust_start_substr(self):
+ self.route_match({"uri": "*bla*bla*"})
+
+ self.assertEqual(self.get(url='/bla_foo')['status'], 404, '/bla_foo')
+
+ def test_route_match_wildcards_adjust_end(self):
+ self.route_match({"uri": "/bla*bla"})
+
+ self.assertEqual(self.get(url='/foo_bla')['status'], 404, '/foo_bla')
+
def test_routes_match_wildcard_right_case_sensitive(self):
self.route_match({"uri": "/bla*"})