]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 2464. Supports a malformation in the URL received
authorFacundo Batista <facundobatista@gmail.com>
Sun, 17 Aug 2008 03:38:39 +0000 (03:38 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Sun, 17 Aug 2008 03:38:39 +0000 (03:38 +0000)
in a redirect.

Lib/urllib2.py
Misc/NEWS

index 121685c0a8dae48c174023552f8ed901adfecb3f..7b209d4c63efb2db1f65ed11ef1e8c484b3f94cd 100644 (file)
@@ -560,6 +560,14 @@ class HTTPRedirectHandler(BaseHandler):
             newurl = headers.getheaders('uri')[0]
         else:
             return
+
+        # fix a possible malformed URL
+        urlparts = urlparse.urlparse(newurl)
+        if not urlparts.path:
+            urlparts = list(urlparts)
+            urlparts[2] = "/"
+        newurl = urlparse.urlunparse(urlparts)
+
         newurl = urlparse.urljoin(req.get_full_url(), newurl)
 
         # XXX Probably want to forget about the state of the current
index 7736ca7c03ead89c7476d672af6df1e6c3345846..08ee9f9d252c56048a3748484c6d0350ab1e5822 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,9 @@ Core and Builtins
 Library
 -------
 
+- Issue 2464. urllib2 now supports a malformation in the URL received
+  in a redirect.
+
 - Silence the DeprecationWarning raised when importing mimetools in
   BaseHTTPServer, cgi (and rfc822), httplib.