Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…everse().
  • Loading branch information...
commit 4fa7f3cdd9bcf50ec4c7f64a31c1dfc02c375f46 1 parent 5d8342f
Baptiste Mispelon authored March 13, 2013
2  django/core/urlresolvers.py
@@ -388,7 +388,7 @@ def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
388 388
                     if len(args) != len(params) + len(prefix_args):
389 389
                         continue
390 390
                     unicode_args = [force_text(val) for val in args]
391  
-                    candidate = (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
  391
+                    candidate = (prefix_norm.replace('%', '%%') + result) % dict(zip(prefix_args + params, unicode_args))
392 392
                 else:
393 393
                     if set(kwargs.keys()) | set(defaults.keys()) != set(params) | set(defaults.keys()) | set(prefix_args):
394 394
                         continue
5  tests/urlpatterns_reverse/tests.py
@@ -183,6 +183,11 @@ def test_prefix_format_char(self):
183 183
         self.assertEqual('/bump%2520map/includes/non_path_include/',
184 184
                reverse('non_path_include', prefix='/bump%20map/'))
185 185
 
  186
+    def test_non_urlsafe_prefix_with_args(self):
  187
+        # Regression for #20022
  188
+        self.assertEqual('/%7Eme/places/1/',
  189
+                reverse('places', args=[1], prefix='/~me/'))
  190
+
186 191
 class ResolverTests(unittest.TestCase):
187 192
     def test_resolver_repr(self):
188 193
         """

0 notes on commit 4fa7f3c

Please sign in to comment.
Something went wrong with that request. Please try again.