1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #31858 -- Reallowed whitespaces in URL paths outside of parameters.

Regression in 22394bd3a1.

Thanks David Smith for the review.
This commit is contained in:
Tim Park
2020-08-29 12:17:58 -07:00
committed by Mariusz Felisiak
parent a629139425
commit ece18207cb
2 changed files with 19 additions and 6 deletions

View File

@@ -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')