Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex URL routes are sorted incorrectly #185

Closed
jace opened this issue May 6, 2012 · 1 comment
Closed

Complex URL routes are sorted incorrectly #185

jace opened this issue May 6, 2012 · 1 comment
Labels
Milestone

Comments

@jace
Copy link
Contributor

jace commented May 6, 2012

Here's a patch to 0.8-maintenance that highlights a route sorting error:

diff --git a/werkzeug/testsuite/routing.py b/werkzeug/testsuite/routing.py
index de3d8bf..f9203d6 100644
--- a/werkzeug/testsuite/routing.py
+++ b/werkzeug/testsuite/routing.py
@@ -175,6 +175,18 @@ class RoutingTestCase(WerkzeugTestCase):
         assert adapter.match('/Files/downloads/werkzeug/0.2.zip') == \
             ('files', {'file':'downloads/werkzeug/0.2.zip'})

+    def test_path_complex(self):
+        map = r.Map([
+            r.Rule('/', endpoint='index'),
+            r.Rule('/static/<path:filename>', endpoint='static'),
+            r.Rule('/<first>/', endpoint='first'),
+            r.Rule('/<first>/<second>/', endpoint='second'),
+            r.Rule('/<first>/<second>/<third>', endpoint='third'),
+        ])
+        adapter = map.bind('example.org', '/')
+        self.assertEquals(adapter.match('/'), ('index', {}))
+        self.assertEquals(adapter.match('/static/img/favicon.ico'), ('static', {'filename': 'img/favicon.ico'}))
+
     def test_dispatch(self):
         env = create_environ('/')
         map = r.Map([

The complex route with three variables gets sorted above the route with a path, resulting in this error:

======================================================================
FAIL: test_path_complex (werkzeug.testsuite.routing.RoutingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jace/Dropbox/Projects/werkzeug/werkzeug/testsuite/routing.py", line 188, in test_path_complex
    self.assertEquals(adapter.match('/static/img/favicon.ico'), ('static', {'filename': 'img/favicon.ico'}))
AssertionError: ('third', {'second': u'img', 'third': u'favicon.ico', 'first': u'static'}) != ('static', {'filename': 'img/favicon.ico'})
@mitsuhiko
Copy link
Contributor

There is a related issue from the sorting of what happens with slash redirects if you have a rule with slash at the end and one without but using different methods.

@pallets pallets deleted a comment from skyline75489 Jun 11, 2017
@davidism davidism closed this as completed Jan 3, 2018
@davidism davidism added this to the 0.14 milestone Jan 3, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants