From cf1d82e9d7a31b4de0dc48f14c71ec9e817db488 Mon Sep 17 00:00:00 2001 From: pgjones Date: Fri, 22 Jul 2022 17:39:43 +0100 Subject: [PATCH] Add a test to demonstrate leaf rules don't consume branches The new router prevents a leaf from consuming the branch if there is a branch match as well. See also https://github.com/pallets/werkzeug/issues/1074. --- tests/test_routing.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_routing.py b/tests/test_routing.py index b1d2ee11a..dc0acfa6f 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -207,6 +207,34 @@ def test_strict_slashes_redirect(): pytest.raises(MethodNotAllowed, adapter.match, "/bar/", method="POST") +def test_strict_slashes_leaves_dont_consume(): + # See issue #1074 + map = r.Map( + [ + r.Rule("/path1", endpoint="leaf"), + r.Rule("/path1/", endpoint="branch"), + r.Rule("/path2", endpoint="leaf", strict_slashes=False), + r.Rule("/path2/", endpoint="branch"), + r.Rule("/path3", endpoint="leaf"), + r.Rule("/path3/", endpoint="branch", strict_slashes=False), + r.Rule("/path4", endpoint="leaf", strict_slashes=False), + r.Rule("/path4/", endpoint="branch", strict_slashes=False), + ], + strict_slashes=False, + ) + + adapter = map.bind("example.org", "/") + + assert adapter.match("/path1", method="GET") == ("leaf", {}) + assert adapter.match("/path1/", method="GET") == ("branch", {}) + assert adapter.match("/path2", method="GET") == ("leaf", {}) + assert adapter.match("/path2/", method="GET") == ("branch", {}) + assert adapter.match("/path3", method="GET") == ("leaf", {}) + assert adapter.match("/path3/", method="GET") == ("branch", {}) + assert adapter.match("/path4", method="GET") == ("leaf", {}) + assert adapter.match("/path4/", method="GET") == ("branch", {}) + + def test_environ_defaults(): environ = create_environ("/foo") assert environ["PATH_INFO"] == "/foo"