From c9f1a12925ef18d82b5f9683d589bb2c1e067650 Mon Sep 17 00:00:00 2001 From: Bas Peschier Date: Sun, 8 Mar 2015 11:07:55 +0100 Subject: Fixed #24013 -- Fixed escaping of reverse() prefix. Prefix was treated as a part of the url pattern, which it is not. Improved tests to conform with RFC 3986 which allows certain characters in path segments without being escaped. --- tests/urlpatterns_reverse/tests.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'tests/urlpatterns_reverse') diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py index 7d08cd21e9..fa553fc6eb 100644 --- a/tests/urlpatterns_reverse/tests.py +++ b/tests/urlpatterns_reverse/tests.py @@ -202,17 +202,24 @@ class URLPatternReverse(TestCase): reverse('non_path_include', prefix='/{{invalid}}/')) def test_prefix_parenthesis(self): - self.assertEqual('/bogus%29/includes/non_path_include/', - reverse('non_path_include', prefix='/bogus)/')) + # Parentheses are allowed and should not cause errors or be escaped + self.assertEqual( + '/bogus)/includes/non_path_include/', + reverse('non_path_include', prefix='/bogus)/') + ) + self.assertEqual( + '/(bogus)/includes/non_path_include/', + reverse('non_path_include', prefix='/(bogus)/') + ) 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/')) + # Regression for #20022, adjusted for #24013 because ~ is an unreserved + # character. Tests whether % is escaped. + self.assertEqual('/%257Eme/places/1/', reverse('places', args=[1], prefix='/%7Eme/')) def test_patterns_reported(self): # Regression for #17076 @@ -227,6 +234,12 @@ class URLPatternReverse(TestCase): # exception self.fail("Expected a NoReverseMatch, but none occurred.") + def test_script_name_escaping(self): + self.assertEqual( + reverse('optional', args=['foo:bar'], prefix='/script:name/'), + '/script:name/optional/foo:bar/' + ) + def test_reverse_returns_unicode(self): name, expected, args, kwargs = test_data[0] self.assertIsInstance( -- cgit v1.3