diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/test_urllib2.py | 19 | ||||
| -rw-r--r-- | Lib/urllib.py | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 46db6b4..b74320d 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -838,6 +838,25 @@ class HandlerTests(unittest.TestCase): p_ds_req = h.do_request_(ds_req) self.assertEqual(p_ds_req.unredirected_hdrs["Host"],"example.com") + def test_fixpath_in_weirdurls(self): + # Issue4493: urllib2 to supply '/' when to urls where path does not + # start with'/' + + h = urllib2.AbstractHTTPHandler() + o = h.parent = MockOpener() + + weird_url = 'http://www.python.org?getspam' + req = Request(weird_url) + newreq = h.do_request_(req) + self.assertEqual(newreq.get_host(),'www.python.org') + self.assertEqual(newreq.get_selector(),'/?getspam') + + url_without_path = 'http://www.python.org' + req = Request(url_without_path) + newreq = h.do_request_(req) + self.assertEqual(newreq.get_host(),'www.python.org') + self.assertEqual(newreq.get_selector(),'') + def test_errors(self): h = urllib2.HTTPErrorProcessor() o = h.parent = MockOpener() diff --git a/Lib/urllib.py b/Lib/urllib.py index d85dedb..1553f9d 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -1052,7 +1052,12 @@ def splithost(url): _hostprog = re.compile('^//([^/?]*)(.*)$') match = _hostprog.match(url) - if match: return match.group(1, 2) + if match: + host_port = match.group(1) + path = match.group(2) + if path and not path.startswith('/'): + path = '/' + path + return host_port, path return None, url _userprog = None |
