Fixed #31459 -- Fixed handling invalid indentifiers in URL path conversion.
This patch adjusted existing tests that used invalid identifiers.
This commit is contained in:
parent
578c03b276
commit
4bb33bb074
|
@ -197,7 +197,7 @@ class RegexPattern(CheckURLMixin):
|
||||||
|
|
||||||
|
|
||||||
_PATH_PARAMETER_COMPONENT_RE = _lazy_re_compile(
|
_PATH_PARAMETER_COMPONENT_RE = _lazy_re_compile(
|
||||||
r'<(?:(?P<converter>[^>:]+):)?(?P<parameter>\w+)>'
|
r'<(?:(?P<converter>[^>:]+):)?(?P<parameter>[^>]+)>'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ class UpdatedToPathTests(SimpleTestCase):
|
||||||
self.assertEqual(len(result), 1)
|
self.assertEqual(len(result), 1)
|
||||||
warning = result[0]
|
warning = result[0]
|
||||||
self.assertEqual(warning.id, '2_0.W001')
|
self.assertEqual(warning.id, '2_0.W001')
|
||||||
expected_msg = "Your URL pattern '(?P<named-group>\\d+)' has a route"
|
expected_msg = "Your URL pattern '(?P<named_group>\\d+)' has a route"
|
||||||
self.assertIn(expected_msg, warning.msg)
|
self.assertIn(expected_msg, warning.msg)
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='check_framework.urls.path_compatibility.beginning_with_caret')
|
@override_settings(ROOT_URLCONF='check_framework.urls.path_compatibility.beginning_with_caret')
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(r'(?P<named-group>\d+)', lambda x: x),
|
path(r'(?P<named_group>\d+)', lambda x: x),
|
||||||
]
|
]
|
||||||
|
|
|
@ -20,7 +20,7 @@ urlpatterns += [
|
||||||
gis_sitemap_views.kml,
|
gis_sitemap_views.kml,
|
||||||
name='django.contrib.gis.sitemaps.views.kml'),
|
name='django.contrib.gis.sitemaps.views.kml'),
|
||||||
path(
|
path(
|
||||||
'sitemaps/kml/<label>/<<model>/<field_name>.kmz',
|
'sitemaps/kml/<label>/<model>/<field_name>.kmz',
|
||||||
gis_sitemap_views.kmz,
|
gis_sitemap_views.kmz,
|
||||||
name='django.contrib.gis.sitemaps.views.kmz'),
|
name='django.contrib.gis.sitemaps.views.kmz'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -249,7 +249,7 @@ class SameNameTests(SimpleTestCase):
|
||||||
|
|
||||||
|
|
||||||
class ParameterRestrictionTests(SimpleTestCase):
|
class ParameterRestrictionTests(SimpleTestCase):
|
||||||
def test_non_identifier_parameter_name_causes_exception(self):
|
def test_integer_parameter_name_causes_exception(self):
|
||||||
msg = (
|
msg = (
|
||||||
"URL route 'hello/<int:1>/' uses parameter name '1' which isn't "
|
"URL route 'hello/<int:1>/' uses parameter name '1' which isn't "
|
||||||
"a valid Python identifier."
|
"a valid Python identifier."
|
||||||
|
@ -257,6 +257,14 @@ class ParameterRestrictionTests(SimpleTestCase):
|
||||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
path(r'hello/<int:1>/', lambda r: None)
|
path(r'hello/<int:1>/', lambda r: None)
|
||||||
|
|
||||||
|
def test_non_identifier_parameter_name_causes_exception(self):
|
||||||
|
msg = (
|
||||||
|
"URL route 'b/<int:book.id>/' uses parameter name 'book.id' which "
|
||||||
|
"isn't a valid Python identifier."
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
|
path(r'b/<int:book.id>/', lambda r: None)
|
||||||
|
|
||||||
def test_allows_non_ascii_but_valid_identifiers(self):
|
def test_allows_non_ascii_but_valid_identifiers(self):
|
||||||
# \u0394 is "GREEK CAPITAL LETTER DELTA", a valid identifier.
|
# \u0394 is "GREEK CAPITAL LETTER DELTA", a valid identifier.
|
||||||
p = path('hello/<str:\u0394>/', lambda r: None)
|
p = path('hello/<str:\u0394>/', lambda r: None)
|
||||||
|
|
Loading…
Reference in New Issue