summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-12-23 05:34:36 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-12-27 09:19:56 +0100
commite42b68debf03223f5e577d80ad8ef6f6441060c0 (patch)
tree6188bbd3d988a100aa57a89cd2ca30302903513f
parent5660267e5b9cc35280e7ecbc59d67fa035e6691d (diff)
Fixed #31114 -- Fixed HttpRequest.build_absolute_uri() crash with reverse_lazy() locations.
-rw-r--r--django/http/request.py3
-rw-r--r--tests/urlpatterns_reverse/tests.py12
2 files changed, 14 insertions, 1 deletions
diff --git a/django/http/request.py b/django/http/request.py
index 5c567b9c46..a0bdf49312 100644
--- a/django/http/request.py
+++ b/django/http/request.py
@@ -191,6 +191,9 @@ class HttpRequest:
# Make it an absolute url (but schemeless and domainless) for the
# edge case that the path starts with '//'.
location = '//%s' % self.get_full_path()
+ else:
+ # Coerce lazy locations.
+ location = str(location)
bits = urlsplit(location)
if not (bits.scheme and bits.netloc):
# Handle the simple, most common case. If the location is absolute
diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py
index d26923ab9d..94c2d40fe8 100644
--- a/tests/urlpatterns_reverse/tests.py
+++ b/tests/urlpatterns_reverse/tests.py
@@ -13,7 +13,9 @@ from django.http import (
HttpRequest, HttpResponsePermanentRedirect, HttpResponseRedirect,
)
from django.shortcuts import redirect
-from django.test import SimpleTestCase, TestCase, override_settings
+from django.test import (
+ RequestFactory, SimpleTestCase, TestCase, override_settings,
+)
from django.test.utils import override_script_prefix
from django.urls import (
NoReverseMatch, Resolver404, ResolverMatch, URLPattern, URLResolver,
@@ -529,6 +531,14 @@ class ReverseLazyTest(TestCase):
'Some URL: /login/'
)
+ def test_build_absolute_uri(self):
+ factory = RequestFactory()
+ request = factory.get('/')
+ self.assertEqual(
+ request.build_absolute_uri(reverse_lazy('some-login-page')),
+ 'http://testserver/login/',
+ )
+
class ReverseLazySettingsTest(AdminScriptTestCase):
"""