diff options
author | Valentin Bartenev <vbart@nginx.com> | 2020-10-07 20:06:30 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2020-10-07 20:06:30 +0300 |
commit | 3f513f434fbe44810ea2352d4ffc7d4d702b3e12 (patch) | |
tree | 3c6161b84ff5df419fd1a4baa77d7e42e90a4d44 | |
parent | 37390d2a3be3646ad5a4c52d46ce93fc8f8a416b (diff) | |
download | unit-3f513f434fbe44810ea2352d4ffc7d4d702b3e12.tar.gz unit-3f513f434fbe44810ea2352d4ffc7d4d702b3e12.tar.bz2 |
Router: fixed "not empty" pattern matching.
The "!" pattern should be opposite to "", i.e. match only non-empty values.
But after 3c00af54b937 it was equal to "!*", which is wrong.
-rw-r--r-- | src/nxt_http_route.c | 4 | ||||
-rw-r--r-- | test/test_routing.py | 15 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 36e003ae..ae91076a 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -1085,10 +1085,6 @@ nxt_http_route_pattern_create(nxt_task_t *task, nxt_mp_t *mp, pattern->negative = 1; pattern->any = 0; - - if (test.length == 0) { - return NXT_OK; - } } if (test.length == 0) { diff --git a/test/test_routing.py b/test/test_routing.py index 734825ef..32a7fbc8 100644 --- a/test/test_routing.py +++ b/test/test_routing.py @@ -118,6 +118,9 @@ class TestRouting(TestApplicationProto): def test_routes_match_negative(self): self.route_match({"uri": "!"}) + assert self.get()['status'] == 200 + + self.route_match({"uri": "!*"}) assert self.get()['status'] == 404 self.route_match({"uri": "!/"}) @@ -1187,6 +1190,18 @@ class TestRouting(TestApplicationProto): assert self.get(url='/?foo=barxx&x%=%')['status'] == 404 def test_routes_match_arguments_negative(self): + self.route_match({"arguments": {"foo": "!"}}) + assert self.get(url='/?bar')['status'] == 404 + assert self.get(url='/?foo')['status'] == 404 + assert self.get(url='/?foo=')['status'] == 404 + assert self.get(url='/?foo=%25')['status'] == 200 + + self.route_match({"arguments": {"foo": "!*"}}) + assert self.get(url='/?bar')['status'] == 404 + assert self.get(url='/?foo')['status'] == 404 + assert self.get(url='/?foo=')['status'] == 404 + assert self.get(url='/?foo=blah')['status'] == 404 + self.route_match({"arguments": {"foo": "!%25"}}) assert self.get(url='/?foo=blah')['status'] == 200 assert self.get(url='/?foo=%')['status'] == 404 |