Permalink
Browse files

Fix #20022: Correctly handle prefixes with url-unsafe characters in r…

…everse().
  • Loading branch information...
1 parent 5d8342f commit 4fa7f3cdd9bcf50ec4c7f64a31c1dfc02c375f46 @bmispelon bmispelon committed Mar 13, 2013
Showing with 6 additions and 1 deletion.
  1. +1 −1 django/core/urlresolvers.py
  2. +5 −0 tests/urlpatterns_reverse/tests.py
View
2 django/core/urlresolvers.py
@@ -388,7 +388,7 @@ def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
if len(args) != len(params) + len(prefix_args):
continue
unicode_args = [force_text(val) for val in args]
- candidate = (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
+ candidate = (prefix_norm.replace('%', '%%') + result) % dict(zip(prefix_args + params, unicode_args))
else:
if set(kwargs.keys()) | set(defaults.keys()) != set(params) | set(defaults.keys()) | set(prefix_args):
continue
View
5 tests/urlpatterns_reverse/tests.py
@@ -183,6 +183,11 @@ def test_prefix_format_char(self):
self.assertEqual('/bump%2520map/includes/non_path_include/',
reverse('non_path_include', prefix='/bump%20map/'))
+ def test_non_urlsafe_prefix_with_args(self):
+ # Regression for #20022
+ self.assertEqual('/%7Eme/places/1/',
+ reverse('places', args=[1], prefix='/~me/'))
+
class ResolverTests(unittest.TestCase):
def test_resolver_repr(self):
"""

0 comments on commit 4fa7f3c

Please sign in to comment.