Skip to content

Commit 7dfb6e2

Browse files
committed
Fix SF # 591713, Fix "file:" URL to have right no. of /'s, by Bruce Atherton
Add a test too. urljoin() would make file:/tmp/foo instead of file:///tmp/foo Bugfix candidate, I will backport.
1 parent e134158 commit 7dfb6e2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Lib/test/test_urlparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ def test_frags(self):
1717
('http', 'www.python.org', '/', '', '', 'abc')),
1818
(RFC1808_BASE,
1919
('http', 'a', '/b/c/d', 'p', 'q', 'f')),
20+
('file:///tmp/junk.txt',
21+
('file', '', '/tmp/junk.txt', '', '', '')),
2022
]:
2123
result = urlparse.urlparse(url)
2224
self.assertEqual(result, expected)
25+
# put it back together and it should be the same
26+
result2 = urlparse.urlunparse(result)
27+
self.assertEqual(result2, url)
2328

2429
def checkJoin(self, base, relurl, expected):
2530
self.assertEqual(urlparse.urljoin(base, relurl), expected)

Lib/urlparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def urlunparse((scheme, netloc, url, params, query, fragment)):
128128
return urlunsplit((scheme, netloc, url, query, fragment))
129129

130130
def urlunsplit((scheme, netloc, url, query, fragment)):
131-
if netloc or (scheme in uses_netloc and url[:2] == '//'):
131+
if netloc or (scheme in uses_netloc and url[:2] != '//'):
132132
if url and url[:1] != '/': url = '/' + url
133133
url = '//' + (netloc or '') + url
134134
if scheme:

0 commit comments

Comments
 (0)