summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-08-17 03:36:03 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2008-08-17 03:36:03 (GMT)
commitf24802c0068f5d1023c77abad328f979c3a13bc6 (patch)
tree0cd39d786e12580ab06d8e064369437a1fa0c600 /Lib
parent8d5d62ff0faa3614ed857077470472a617dd29ba (diff)
downloadcpython-f24802c0068f5d1023c77abad328f979c3a13bc6.zip
cpython-f24802c0068f5d1023c77abad328f979c3a13bc6.tar.gz
cpython-f24802c0068f5d1023c77abad328f979c3a13bc6.tar.bz2
Issue 2464. Supports a malformation in the URL received
in a redirect.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib/request.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 428be4a..889d9642 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -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