summaryrefslogtreecommitdiff
path: root/tests/urlpatterns
diff options
context:
space:
mode:
authorTim Park <timpark0807@gmail.com>2020-08-29 12:17:58 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-02 10:24:14 +0200
commitece18207cbb64dd89014e279ac636a6c9829828e (patch)
tree0aeee2b07eb0eaab4bce5f93f4db77f990c56802 /tests/urlpatterns
parenta6291394256aa758d74eec9ce0cfae8aea6475f2 (diff)
downloaddjango-ece18207cbb64dd89014e279ac636a6c9829828e.tar.gz
Fixed #31858 -- Reallowed whitespaces in URL paths outside of parameters.
Regression in 22394bd3a18a7d9a8957a0b431f8ae4e5ca03a8c. Thanks David Smith for the review.
Diffstat (limited to 'tests/urlpatterns')
-rw-r--r--tests/urlpatterns/tests.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/urlpatterns/tests.py b/tests/urlpatterns/tests.py
index 54b7e09813..b6b23ade9e 100644
--- a/tests/urlpatterns/tests.py
+++ b/tests/urlpatterns/tests.py
@@ -1,3 +1,4 @@
+import string
import uuid
from django.conf.urls import url as conf_url
@@ -142,10 +143,19 @@ class SimplifiedURLTests(SimpleTestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
path('foo/<nonexistent:var>/', empty_view)
- def test_space_in_route(self):
- msg = "URL route 'space/<int: num>' cannot contain whitespace."
- with self.assertRaisesMessage(ImproperlyConfigured, msg):
- path('space/<int: num>', empty_view)
+ def test_whitespace_in_route(self):
+ msg = (
+ "URL route 'space/<int:num>/extra/<str:%stest>' cannot contain "
+ "whitespace in angle brackets <…>"
+ )
+ for whitespace in string.whitespace:
+ with self.subTest(repr(whitespace)):
+ with self.assertRaisesMessage(ImproperlyConfigured, msg % whitespace):
+ path('space/<int:num>/extra/<str:%stest>' % whitespace, empty_view)
+ # Whitespaces are valid in paths.
+ p = path('space%s/<int:num>/' % string.whitespace, empty_view)
+ match = p.resolve('space%s/1/' % string.whitespace)
+ self.assertEqual(match.kwargs, {'num': 1})
@override_settings(ROOT_URLCONF='urlpatterns.converter_urls')