Fixed #18314 -- request.build_absolute_uri() not handling paths starting with // #1866

Closed
wants to merge 1 commit into
from

2 participants

@unaizalakain

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).

@timgraham timgraham commented on an outdated diff Jun 6, 2014
docs/releases/1.7.txt
@@ -509,6 +509,11 @@ Requests
* The new :attr:`HttpRequest.scheme <django.http.HttpRequest.scheme>` attribute
specifies the scheme of the request (``http`` or ``https`` normally).
+* ``WSGIRequest`` now respects paths starting with ``//``.
+
+* The ``HttpRequest.get_absolute_uri()`` method now handles paths starting with
@timgraham
Django member
timgraham added a line comment Jun 6, 2014

build_absolute_uri() (wouldn't hurt ot make it a link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@timgraham timgraham commented on an outdated diff Jun 6, 2014
tests/requests/tests.py
@@ -753,3 +753,66 @@ def fail_horribly():
# works again.
signals.request_finished.send(sender=self.__class__)
self.assertEqual(len(connection.transaction_state), 0)
+
+
+class BuildAbsoluteURITestCase(TestCase):
+ """
+ Regression tests for ticket # 18314.
@timgraham
Django member
timgraham added a line comment Jun 6, 2014

no space after #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@timgraham timgraham commented on an outdated diff Jun 6, 2014
tests/requests/tests.py
@@ -753,3 +753,66 @@ def fail_horribly():
# works again.
signals.request_finished.send(sender=self.__class__)
self.assertEqual(len(connection.transaction_state), 0)
+
+
+class BuildAbsoluteURITestCase(TestCase):
+ """
+ Regression tests for ticket # 18314.
+ """
+ def setUp(self):
+ """
+ Attaches a request factory.
@timgraham
Django member
timgraham added a line comment Jun 6, 2014

obvious comment can be omitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@timgraham timgraham commented on an outdated diff Jun 6, 2014
tests/requests/tests.py
+ Regression tests for ticket # 18314.
+ """
+ def setUp(self):
+ """
+ Attaches a request factory.
+ """
+ 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('////django-ate-my-baby')
@timgraham
Django member
timgraham added a line comment Jun 6, 2014

choosing a different string wouldn't hurt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@timgraham
Django member

Could you rebase and move release notes to 1.8? Also I would thank SmileyChris for the initial patch in the commit message.

@unaizalakain unaizalakain Fixed #18314 -- request.build_absolute_uri() not handling paths start…
…ing 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.
fc944be
@unaizalakain

Thanks for the review @timgraham!

@timgraham
Django member

buildbot, test this please.

@timgraham
Django member

merged in 11284a6.

@timgraham timgraham closed this Jun 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment