diff options
| author | Unai Zalakain <unai@gisa-elkartea.org> | 2013-11-04 00:34:11 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-06-07 08:59:02 -0400 |
| commit | 11284a63d48c84f1d60b5686d55cf8a9f8d64422 (patch) | |
| tree | 6c16ab34fae64bbdc37ac7d5f990b979598b7a17 /tests | |
| parent | 9ed4a8c6b1a552a03fd27b77f1b742e3f9c66bde (diff) | |
Fixed #18314 -- Corrected request.build_absolute_uri() handling of paths starting with //
``HttpRequest.build_absolute_uri()`` now correctly handles paths starting with ``//``.
``WSGIRequest`` now doesn't remove all the leading slashes either,
because ``http://test/server`` and http://test//server`` aren't the same thing
(RFC2396).
Thanks to SmileyChris for the initial patch.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/requests/tests.py | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/requests/tests.py b/tests/requests/tests.py index cf90fb1f1b..3f30f75eea 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -10,7 +10,7 @@ from django.core.exceptions import SuspiciousOperation from django.core.handlers.wsgi import WSGIRequest, LimitedStream from django.http import (HttpRequest, HttpResponse, parse_cookie, build_request_repr, UnreadablePostError, RawPostDataException) -from django.test import SimpleTestCase, override_settings +from django.test import SimpleTestCase, RequestFactory, override_settings from django.test.client import FakePayload from django.test.utils import str_prefix from django.utils import six @@ -693,3 +693,64 @@ class HostValidationTests(SimpleTestCase): msg_suggestion2 % "invalid_hostname.com", request.get_host ) + + +class BuildAbsoluteURITestCase(SimpleTestCase): + """ + Regression tests for ticket #18314. + """ + + def setUp(self): + self.factory = RequestFactory() + + def test_build_absolute_uri_no_location(self): + """ + Ensures that ``request.build_absolute_uri()`` returns the proper value + when the ``location`` argument is not provided, and ``request.path`` + begins with //. + """ + # //// is needed to create a request with a path beginning with // + request = self.factory.get('////absolute-uri') + self.assertEqual( + request.build_absolute_uri(), + 'http://testserver//absolute-uri' + ) + + def test_build_absolute_uri_absolute_location(self): + """ + Ensures that ``request.build_absolute_uri()`` returns the proper value + when an absolute URL ``location`` argument is provided, and + ``request.path`` begins with //. + """ + # //// is needed to create a request with a path beginning with // + request = self.factory.get('////absolute-uri') + self.assertEqual( + request.build_absolute_uri(location='http://example.com/?foo=bar'), + 'http://example.com/?foo=bar' + ) + + def test_build_absolute_uri_schema_relative_location(self): + """ + Ensures that ``request.build_absolute_uri()`` returns the proper value + when a schema-relative URL ``location`` argument is provided, and + ``request.path`` begins with //. + """ + # //// is needed to create a request with a path beginning with // + request = self.factory.get('////absolute-uri') + self.assertEqual( + request.build_absolute_uri(location='//example.com/?foo=bar'), + 'http://example.com/?foo=bar' + ) + + def test_build_absolute_uri_relative_location(self): + """ + Ensures that ``request.build_absolute_uri()`` returns the proper value + when a relative URL ``location`` argument is provided, and + ``request.path`` begins with //. + """ + # //// is needed to create a request with a path beginning with // + request = self.factory.get('////absolute-uri') + self.assertEqual( + request.build_absolute_uri(location='/foo/bar/'), + 'http://testserver/foo/bar/' + ) |
