Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6497aa3e
Commit
6497aa3e
authored
Jan 04, 2012
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue13696 - Fix 302 Redirection for Relative urls.
parent
b7ffed8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
2 deletions
+17
-2
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+13
-0
Lib/urllib/request.py
Lib/urllib/request.py
+2
-2
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_urllib2.py
View file @
6497aa3e
...
...
@@ -1059,6 +1059,19 @@ class HandlerTests(unittest.TestCase):
MockHeaders
({
"location"
:
valid_url
}))
self
.
assertEqual
(
o
.
req
.
get_full_url
(),
valid_url
)
def
test_relative_redirect
(
self
):
from_url
=
"http://example.com/a.html"
relative_url
=
"/b.html"
h
=
urllib
.
request
.
HTTPRedirectHandler
()
o
=
h
.
parent
=
MockOpener
()
req
=
Request
(
from_url
)
req
.
timeout
=
socket
.
_GLOBAL_DEFAULT_TIMEOUT
valid_url
=
urllib
.
parse
.
urljoin
(
from_url
,
relative_url
)
h
.
http_error_302
(
req
,
MockFile
(),
302
,
"That's fine"
,
MockHeaders
({
"location"
:
valid_url
}))
self
.
assertEqual
(
o
.
req
.
get_full_url
(),
valid_url
)
def
test_cookie_redirect
(
self
):
# cookies shouldn't leak into redirected requests
from
http.cookiejar
import
CookieJar
...
...
Lib/urllib/request.py
View file @
6497aa3e
...
...
@@ -552,7 +552,7 @@ class HTTPRedirectHandler(BaseHandler):
# For security reasons we don't allow redirection to anything other
# than http, https or ftp.
if urlparts.scheme not in ('http', 'https', 'ftp'):
if urlparts.scheme not in ('http', 'https', 'ftp'
, ''
):
raise HTTPError(
newurl, code,
"
%
s
-
Redirection
to
url
'%s'
is
not
allowed
" % (msg, newurl),
...
...
@@ -1935,7 +1935,7 @@ class FancyURLopener(URLopener):
# We are using newer HTTPError with older redirect_internal method
# This older method will get deprecated in 3.3
if
urlparts
.
scheme
not
in
(
'http'
,
'https'
,
'ftp'
):
if
urlparts
.
scheme
not
in
(
'http'
,
'https'
,
'ftp'
,
''
):
raise
HTTPError
(
newurl
,
errcode
,
errmsg
+
" Redirection to url '%s' is not allowed."
%
newurl
,
...
...
Misc/NEWS
View file @
6497aa3e
...
...
@@ -97,6 +97,8 @@ Core and Builtins
Library
-------
- Issue #13696: Fix the 302 Relative URL Redirection problem.
- Issue #13636: Weak ciphers are now disabled by default in the ssl module
(except when SSLv2 is explicitly asked for).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment