Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 239a042

Browse files
committed
merge from 3.2
2 parents 606e19d + 6497aa3 commit 239a042

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/test/test_urllib2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,19 @@ def test_invalid_redirect(self):
10761076
MockHeaders({"location": valid_url}))
10771077
self.assertEqual(o.req.get_full_url(), valid_url)
10781078

1079+
def test_relative_redirect(self):
1080+
from_url = "http://example.com/a.html"
1081+
relative_url = "/b.html"
1082+
h = urllib.request.HTTPRedirectHandler()
1083+
o = h.parent = MockOpener()
1084+
req = Request(from_url)
1085+
req.timeout = socket._GLOBAL_DEFAULT_TIMEOUT
1086+
1087+
valid_url = urllib.parse.urljoin(from_url,relative_url)
1088+
h.http_error_302(req, MockFile(), 302, "That's fine",
1089+
MockHeaders({"location": valid_url}))
1090+
self.assertEqual(o.req.get_full_url(), valid_url)
1091+
10791092
def test_cookie_redirect(self):
10801093
# cookies shouldn't leak into redirected requests
10811094
from http.cookiejar import CookieJar

Lib/urllib/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def http_error_302(self, req, fp, code, msg, headers):
572572
# For security reasons we don't allow redirection to anything other
573573
# than http, https or ftp.
574574

575-
if urlparts.scheme not in ('http', 'https', 'ftp'):
575+
if urlparts.scheme not in ('http', 'https', 'ftp', ''):
576576
raise HTTPError(
577577
newurl, code,
578578
"%s - Redirection to url '%s' is not allowed" % (msg, newurl),
@@ -1963,7 +1963,7 @@ def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
19631963
# We are using newer HTTPError with older redirect_internal method
19641964
# This older method will get deprecated in 3.3
19651965

1966-
if urlparts.scheme not in ('http', 'https', 'ftp'):
1966+
if urlparts.scheme not in ('http', 'https', 'ftp', ''):
19671967
raise HTTPError(newurl, errcode,
19681968
errmsg +
19691969
" Redirection to url '%s' is not allowed." % newurl,

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ Core and Builtins
422422
Library
423423
-------
424424

425+
- Issue #13696: Fix the 302 Relative URL Redirection problem.
426+
425427
- Issue #13636: Weak ciphers are now disabled by default in the ssl module
426428
(except when SSLv2 is explicitly asked for).
427429

0 commit comments

Comments
 (0)