Skip to content

Commit

Permalink
Issue 2464. Supports a malformation in the URL received
Browse files Browse the repository at this point in the history
in a redirect.
  • Loading branch information
facundobatista committed Aug 17, 2008
1 parent 8d5d62f commit f24802c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
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
Expand Down Expand Up @@ -535,6 +535,14 @@ def http_error_302(self, req, fp, code, msg, headers):
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
Expand Down

0 comments on commit f24802c

Please sign in to comment.