]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Wed, 25 Sep 2002 19:22:10 +0000 (19:22 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Wed, 25 Sep 2002 19:22:10 +0000 (19:22 +0000)
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
Lib/test/test_urlparse.py
Lib/urlparse.py

index c478783295b1cb97c236284e0fef79e6fcd11594..8c6347496dd27c8e1dfb028a3c7521769e62c72e 100644 (file)
@@ -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
 
index 48c526bf394599b9d5d7ff424a7e213277e7e468..b0a38b585c7e98fe04a2b8fd14eb260d5af4da2a 100644 (file)
@@ -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):
index ee99645d59b7ce3937021c203a6c8b3fd16c5953..6361937a93191a23ae1c6ebcbcdf5c1e30beecb9 100644 (file)
@@ -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: