mirror of https://github.com/django/django.git
Fixed #29667 -- Prohibited whitespaces in path() URLs.
This commit is contained in:
parent
cece802dbb
commit
22394bd3a1
|
@ -8,6 +8,7 @@ attributes of the resolved URL match.
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
@ -206,6 +207,8 @@ def _route_to_regex(route, is_endpoint=False):
|
||||||
For example, 'foo/<int:pk>' returns '^foo\\/(?P<pk>[0-9]+)'
|
For example, 'foo/<int:pk>' returns '^foo\\/(?P<pk>[0-9]+)'
|
||||||
and {'pk': <django.urls.converters.IntConverter>}.
|
and {'pk': <django.urls.converters.IntConverter>}.
|
||||||
"""
|
"""
|
||||||
|
if not set(route).isdisjoint(string.whitespace):
|
||||||
|
raise ImproperlyConfigured("URL route '%s' cannot contain whitespace." % route)
|
||||||
original_route = route
|
original_route = route
|
||||||
parts = ['^']
|
parts = ['^']
|
||||||
converters = {}
|
converters = {}
|
||||||
|
|
|
@ -130,6 +130,11 @@ class SimplifiedURLTests(SimpleTestCase):
|
||||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
path('foo/<nonexistent:var>/', empty_view)
|
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)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='urlpatterns.converter_urls')
|
@override_settings(ROOT_URLCONF='urlpatterns.converter_urls')
|
||||||
class ConverterTests(SimpleTestCase):
|
class ConverterTests(SimpleTestCase):
|
||||||
|
|
Loading…
Reference in New Issue