]> granicus.if.org Git - python/commitdiff
Issue 2464. Supports a malformation in the URL received
authorFacundo Batista <facundobatista@gmail.com>
Sun, 17 Aug 2008 03:36:03 +0000 (03:36 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Sun, 17 Aug 2008 03:36:03 +0000 (03:36 +0000)
in a redirect.

Lib/urllib/request.py

index 428be4acef67350f233c770c66b4897217914f12..889d96420926f0bfcd270ffe566f8c8ffa3042f7 100644 (file)
@@ -100,7 +100,7 @@ from urllib.error import URLError, HTTPError, ContentTooShortError
 from urllib.parse import (
     urlparse, urlsplit, urljoin, unwrap, quote, unquote,
     splittype, splithost, splitport, splituser, splitpasswd,
-    splitattr, splitquery, splitvalue, to_bytes)
+    splitattr, splitquery, splitvalue, to_bytes, urlunparse)
 from urllib.response import addinfourl, addclosehook
 
 # check for SSL
@@ -535,6 +535,14 @@ class HTTPRedirectHandler(BaseHandler):
             newurl = headers["uri"]
         else:
             return
+
+        # fix a possible malformed URL
+        urlparts = urlparse(newurl)
+        if not urlparts.path:
+            urlparts = list(urlparts)
+            urlparts[2] = "/"
+        newurl = urlunparse(urlparts)
+
         newurl = urljoin(req.get_full_url(), newurl)
 
         # XXX Probably want to forget about the state of the current