cpython: 901e4e52b20a (original) (raw)
Mercurial > cpython
changeset 92517:901e4e52b20a
Issue #22278: Fix urljoin problem with relative urls, a regression observed after changes to issue22118 were submitted. Patch contributed by Demian Brecht and reviewed by Antoine Pitrou. [#22278]
Senthil Kumaran senthil@uthcode.com | |
---|---|
date | Mon, 22 Sep 2014 15:49:16 +0800 |
parents | 850a62354402 |
children | 00a11276ae6d |
files | Lib/test/test_urlparse.py Lib/urllib/parse.py Misc/NEWS |
diffstat | 3 files changed, 20 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_urlparse.py 12 Lib/urllib/parse.py 6 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -380,6 +380,18 @@ class UrlParseTestCase(unittest.TestCase # self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g')[](#l1.4) # self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g')[](#l1.5)
# test for issue22118 duplicate slashes[](#l1.7)
self.checkJoin(SIMPLE_BASE + '/', 'foo', SIMPLE_BASE + '/foo')[](#l1.8)
# Non-RFC-defined tests, covering variations of base and trailing[](#l1.10)
# slashes[](#l1.11)
self.checkJoin('http://a/b/c/d/e/', '../../f/g/', 'http://a/b/c/f/g/')[](#l1.12)
self.checkJoin('http://a/b/c/d/e', '../../f/g/', 'http://a/b/f/g/')[](#l1.13)
self.checkJoin('http://a/b/c/d/e/', '/../../f/g/', 'http://a/f/g/')[](#l1.14)
self.checkJoin('http://a/b/c/d/e', '/../../f/g/', 'http://a/f/g/')[](#l1.15)
self.checkJoin('http://a/b/c/d/e/', '../../f/g', 'http://a/b/c/f/g')[](#l1.16)
self.checkJoin('http://a/b/', '../../f/g/', 'http://a/f/g/')[](#l1.17)
+ def test_RFC2732(self): str_cases = [ ('http://Test.python.org:5432/foo/', 'test.python.org', 5432),
--- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -443,6 +443,10 @@ def urljoin(base, url, allow_fragments=T segments = path.split('/') else: segments = base_parts + path.split('/')
# filter out elements that would cause redundant slashes on re-joining[](#l2.7)
# the resolved_path[](#l2.8)
segments = segments[0:1] + [[](#l2.9)
s for s in segments[1:-1] if len(s) > 0] + segments[-1:][](#l2.10)
resolved_path = [] @@ -465,7 +469,7 @@ def urljoin(base, url, allow_fragments=T resolved_path.append('') return _coerce_result(urlunparse((scheme, netloc, '/'.join(
resolved_path), params, query, fragment)))[](#l2.18)
resolved_path) or '/', params, query, fragment)))[](#l2.19)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -137,6 +137,9 @@ Core and Builtins Library ------- +- Issue #22278: Fix urljoin problem with relative urls, a regression observed