From 76b993a117b61c41584e95149a67d8a1e9f49dd1 Mon Sep 17 00:00:00 2001 From: daniel a rios Date: Wed, 24 Apr 2019 22:51:47 +0200 Subject: Fixed #26431 -- Prevented django.urls.resolve() from returning missing optional parameters. Previous behavior was inconsistent with django.urls.reverse() and caused that translate_url() created an incorrect URL when an optional parameter was missing. --- tests/urlpatterns/tests.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tests/urlpatterns') diff --git a/tests/urlpatterns/tests.py b/tests/urlpatterns/tests.py index 66212d7df8..214739f678 100644 --- a/tests/urlpatterns/tests.py +++ b/tests/urlpatterns/tests.py @@ -55,10 +55,18 @@ class SimplifiedURLTests(SimpleTestCase): self.assertEqual(match.route, '^regex/(?P[0-9]+)/$') def test_re_path_with_optional_parameter(self): - match = resolve('/regex_optional/1/2/') - self.assertEqual(match.url_name, 'regex_optional') - self.assertEqual(match.kwargs, {'arg1': '1', 'arg2': '2'}) - self.assertEqual(match.route, r'^regex_optional/(?P\d+)/(?:(?P\d+)/)?') + for url, kwargs in ( + ('/regex_optional/1/2/', {'arg1': '1', 'arg2': '2'}), + ('/regex_optional/1/', {'arg1': '1'}), + ): + with self.subTest(url=url): + match = resolve(url) + self.assertEqual(match.url_name, 'regex_optional') + self.assertEqual(match.kwargs, kwargs) + self.assertEqual( + match.route, + r'^regex_optional/(?P\d+)/(?:(?P\d+)/)?', + ) def test_path_lookup_with_inclusion(self): match = resolve('/included_urls/extra/something/') -- cgit v1.3