diff options
author | Facundo Batista <facundobatista@gmail.com> | 2008-08-14 16:51:00 (GMT) |
---|---|---|
committer | Facundo Batista <facundobatista@gmail.com> | 2008-08-14 16:51:00 (GMT) |
commit | 67d1981c5172e840ac3e2fc3505ce9c3abe5cd63 (patch) | |
tree | ef2d24d280373c3739dcb2ceff0edd07c422f266 | |
parent | 8401eec7fab006b65b82a213f3312b96e0ae29e8 (diff) | |
download | cpython-67d1981c5172e840ac3e2fc3505ce9c3abe5cd63.zip cpython-67d1981c5172e840ac3e2fc3505ce9c3abe5cd63.tar.gz cpython-67d1981c5172e840ac3e2fc3505ce9c3abe5cd63.tar.bz2 |
Issue 1432. Fixes a bug caused because of the evolution
of the RFC that describes the behaviour. Note that we now
have the same behaviour than the current browsers.
-rw-r--r-- | Lib/test/test_urlparse.py | 11 | ||||
-rw-r--r-- | Lib/urlparse.py | 15 |
2 files changed, 21 insertions, 5 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index fff8408..e7d9e5a 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -6,6 +6,7 @@ import urlparse RFC1808_BASE = "http://a/b/c/d;p?q#f" RFC2396_BASE = "http://a/b/c/d;p?q" +RFC3986_BASE = "http://a/b/c/d;p?q" class UrlParseTestCase(unittest.TestCase): @@ -167,8 +168,6 @@ class UrlParseTestCase(unittest.TestCase): def test_RFC2396(self): # cases from RFC 2396 - self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y') - self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x') self.checkJoin(RFC2396_BASE, 'g:h', 'g:h') self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g') @@ -210,6 +209,14 @@ class UrlParseTestCase(unittest.TestCase): self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x') self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x') + #The following scenarios have been updated in RFC3986 + #self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y') + #self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x') + + def test_RFC3986(self): + self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y') + self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x') + def test_urldefrag(self): for url, defrag, frag in [ ('http://python.org#frag', 'http://python.org', 'frag'), diff --git a/Lib/urlparse.py b/Lib/urlparse.py index c384db7..1914304 100644 --- a/Lib/urlparse.py +++ b/Lib/urlparse.py @@ -217,9 +217,18 @@ def urljoin(base, url, allow_fragments=True): if path[:1] == '/': return urlunparse((scheme, netloc, path, params, query, fragment)) - if not (path or params or query): - return urlunparse((scheme, netloc, bpath, - bparams, bquery, fragment)) + if not path: + path = bpath + if not params: + params = bparams + else: + path = path[:-1] + return urlunparse((scheme, netloc, path, + params, query, fragment)) + if not query: + query = bquery + return urlunparse((scheme, netloc, path, + params, query, fragment)) segments = bpath.split('/')[:-1] + path.split('/') # XXX The stuff below is bogus in various ways... if segments[-1] == '.': |