From bd1ac013fe4dc5ec6b6a5c2ee9cc63ba8ab171be Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Wed, 25 Sep 2002 19:22:10 +0000 Subject: [PATCH] Backport: 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 --- Lib/test/output/test_urlparse | 1 + Lib/test/test_urlparse.py | 5 +++++ Lib/urlparse.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/test/output/test_urlparse b/Lib/test/output/test_urlparse index c478783295b1..8c6347496dd2 100644 --- a/Lib/test/output/test_urlparse +++ b/Lib/test/output/test_urlparse @@ -3,6 +3,7 @@ http://www.python.org = ('http', 'www.python.org', '', '', '', '') http://www.python.org#abc = ('http', 'www.python.org', '', '', '', 'abc') http://www.python.org/#abc = ('http', 'www.python.org', '/', '', '', 'abc') http://a/b/c/d;p?q#f = ('http', 'a', '/b/c/d', 'p', 'q', 'f') +file:///tmp/junk.txt = ('file', '', '/tmp/junk.txt', '', '', '') urlparse.urljoin() tests diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 48c526bf3945..b0a38b585c7e 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -12,6 +12,8 @@ for url, expected in [('http://www.python.org', ('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) print "%-13s = %r" % (url, result) @@ -20,6 +22,9 @@ for url, expected in [('http://www.python.org', print "urlparse(%r)" % url print ("expected %r,\n" " got %r") % (expected, result) + # put it back together and it should be the same + result2 = urlparse.urlunparse(result) + assert(result2 == url) print def checkJoin(relurl, expected): diff --git a/Lib/urlparse.py b/Lib/urlparse.py index ee99645d59b7..6361937a9319 100644 --- a/Lib/urlparse.py +++ b/Lib/urlparse.py @@ -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: -- 2.47.3