summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib2.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 121685c..7b209d4 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -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