]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix SF # 591713, Fix "file:" URL to have right no. of /'s, by Bruce Atherton
authorNeal Norwitz <nnorwitz@gmail.com>
Wed, 25 Sep 2002 19:20:12 +0000 (19:20 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Wed, 25 Sep 2002 19:20:12 +0000 (19:20 +0000)
Add a test too.  urljoin() would make file:/tmp/foo instead of file:///tmp/foo

Bugfix candidate, I will backport.

Lib/test/test_urlparse.py
Lib/urlparse.py

index d3efa9e1860f5ab2a40cf98922bc1a675e6248bf..b821879397979d4d2403c1e8e1edd1b7379f4fb9 100644 (file)
@@ -17,9 +17,14 @@ class UrlParseTestCase(unittest.TestCase):
                                ('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)
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: