Skip to content

Commit

Permalink
Fix SF # 591713, Fix "file:" URL to have right no. of /'s, by Bruce A…
Browse files Browse the repository at this point in the history
…therton

Add a test too.  urljoin() would make file:/tmp/foo instead of file:///tmp/foo

Bugfix candidate, I will backport.
  • Loading branch information
nnorwitz committed Sep 25, 2002
1 parent e134158 commit 7dfb6e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Lib/test/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ def test_frags(self):
('http', 'www.python.org', '/', '', '', 'abc')),
(RFC1808_BASE,
('http', 'a', '/b/c/d', 'p', 'q', 'f')),
('file:///tmp/junk.txt',
('file', '', '/tmp/junk.txt', '', '', '')),
]:
result = urlparse.urlparse(url)
self.assertEqual(result, expected)
# put it back together and it should be the same
result2 = urlparse.urlunparse(result)
self.assertEqual(result2, url)

def checkJoin(self, base, relurl, expected):
self.assertEqual(urlparse.urljoin(base, relurl), expected)
Expand Down
2 changes: 1 addition & 1 deletion Lib/urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def urlunparse((scheme, netloc, url, params, query, fragment)):
return urlunsplit((scheme, netloc, url, query, fragment))

def urlunsplit((scheme, netloc, url, query, fragment)):
if netloc or (scheme in uses_netloc and url[:2] == '//'):
if netloc or (scheme in uses_netloc and url[:2] != '//'):
if url and url[:1] != '/': url = '/' + url
url = '//' + (netloc or '') + url
if scheme:
Expand Down

0 comments on commit 7dfb6e2

Please sign in to comment.