Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986

This commit is contained in:
Senthil Kumaran 2010-02-19 07:32:48 +00:00
parent cc43b56960
commit 4e78de89d0
2 changed files with 12 additions and 2 deletions

View File

@ -141,7 +141,7 @@ class UrlParseTestCase(unittest.TestCase):
(base, relurl, expected))
def test_unparse_parse(self):
for u in ['Python', './Python']:
for u in ['Python', './Python','x-newscheme://foo.com/stuff']:
self.assertEqual(urlparse.urlunsplit(urlparse.urlsplit(u)), u)
self.assertEqual(urlparse.urlunparse(urlparse.urlparse(u)), u)
@ -353,6 +353,15 @@ class UrlParseTestCase(unittest.TestCase):
self.assertEqual(urlparse.urlparse("http://example.com?blahblah=/foo"),
('http', 'example.com', '', '', 'blahblah=/foo', ''))
def test_anyscheme(self):
# Issue 7904: s3://foo.com/stuff has netloc "foo.com".
self.assertEqual(urlparse.urlparse("s3://foo.com/stuff"),
('s3','foo.com','/stuff','','',''))
self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff"),
('x-newscheme','foo.com','/stuff','','',''))
def test_main():
test_support.run_unittest(UrlParseTestCase)

View File

@ -163,7 +163,8 @@ def urlsplit(url, scheme='', allow_fragments=True):
break
else:
scheme, url = url[:i].lower(), url[i+1:]
if scheme in uses_netloc and url[:2] == '//':
if url[:2] == '//':
netloc, url = _splitnetloc(url, 2)
if allow_fragments and scheme in uses_fragment and '#' in url:
url, fragment = url.split('#', 1)