From 01384ce36c3fddfbcc5af6e1108bdb8cd3e9389d Mon Sep 17 00:00:00 2001 From: Tilmann Becker Date: Tue, 19 Dec 2017 23:50:23 +0100 Subject: [PATCH] Fixed #28947 -- Fixed crash when coercing a translatable URL pattern to str. Regression in df41b5a05d4e00e80e73afe629072e37873e767a. --- django/urls/resolvers.py | 4 ++-- docs/releases/2.0.1.txt | 3 +++ tests/urlpatterns/test_resolvers.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/urlpatterns/test_resolvers.py diff --git a/django/urls/resolvers.py b/django/urls/resolvers.py index 661525c6d1..758eaef218 100644 --- a/django/urls/resolvers.py +++ b/django/urls/resolvers.py @@ -182,7 +182,7 @@ class RegexPattern(CheckURLMixin): ) def __str__(self): - return self._regex + return str(self._regex) _PATH_PARAMETER_COMPONENT_RE = re.compile( @@ -270,7 +270,7 @@ class RoutePattern(CheckURLMixin): return re.compile(_route_to_regex(route, self._is_endpoint)[0]) def __str__(self): - return self._route + return str(self._route) class LocalePrefixPattern: diff --git a/docs/releases/2.0.1.txt b/docs/releases/2.0.1.txt index 9d2163b2b6..19164dab8a 100644 --- a/docs/releases/2.0.1.txt +++ b/docs/releases/2.0.1.txt @@ -31,3 +31,6 @@ Bugfixes trailing zeros in the fractional part truncated (:ticket:`28915`). * Fixed crash in the ``testserver`` command startup (:ticket:`28941`). + +* Fixed crash when coercing a translatable URL pattern to ``str`` + (:ticket:`28947`). diff --git a/tests/urlpatterns/test_resolvers.py b/tests/urlpatterns/test_resolvers.py new file mode 100644 index 0000000000..a32e8edaf7 --- /dev/null +++ b/tests/urlpatterns/test_resolvers.py @@ -0,0 +1,15 @@ +from django.test import SimpleTestCase +from django.urls.resolvers import RegexPattern, RoutePattern +from django.utils.translation import gettext_lazy as _ + + +class RegexPatternTests(SimpleTestCase): + + def test_str(self): + self.assertEqual(str(RegexPattern(_('^translated/$'))), '^translated/$') + + +class RoutePatternTests(SimpleTestCase): + + def test_str(self): + self.assertEqual(str(RoutePattern(_('translated/'))), 'translated/')