diff -r ea401e7c55e4 Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py Thu Sep 18 21:37:26 2014 +0800 +++ b/Lib/test/test_urlparse.py Thu Sep 18 07:49:33 2014 -0700 @@ -380,6 +380,19 @@ # self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g') # self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g') + # test for issue22118 duplicate slashes + self.checkJoin(SIMPLE_BASE + '/', 'foo', SIMPLE_BASE + '/foo') + + # Non-RFC-specific tests, covering variations of base and + # Non-RFC-defined tests, covering variations of base and trailing + # slashes + self.checkJoin('http://a/b/c/d/e/', '../../f/g/', 'http://a/b/c/f/g/') + self.checkJoin('http://a/b/c/d/e', '../../f/g/', 'http://a/b/f/g/') + self.checkJoin('http://a/b/c/d/e/', '/../../f/g/', 'http://a/f/g/') + self.checkJoin('http://a/b/c/d/e', '/../../f/g/', 'http://a/f/g/') + self.checkJoin('http://a/b/c/d/e/', '../../f/g', 'http://a/b/c/f/g') + self.checkJoin('http://a/b/', '../../f/g/', 'http://a/f/g/') + def test_RFC2732(self): str_cases = [ ('http://Test.python.org:5432/foo/', 'test.python.org', 5432), diff -r ea401e7c55e4 Lib/urllib/parse.py --- a/Lib/urllib/parse.py Thu Sep 18 21:37:26 2014 +0800 +++ b/Lib/urllib/parse.py Thu Sep 18 07:49:33 2014 -0700 @@ -443,10 +443,14 @@ segments = path.split('/') else: segments = base_parts + path.split('/') + # filter out elements that would cause redundant slashes on re-joining + # the resolved_path + segments = segments[0:1] + [ + s for s in segments[1:-1] if len(s) > 0] + segments[-1:] resolved_path = [] - for seg in segments: + for idx, seg in enumerate(segments): if seg == '..': try: resolved_path.pop() @@ -465,7 +469,7 @@ resolved_path.append('') return _coerce_result(urlunparse((scheme, netloc, '/'.join( - resolved_path), params, query, fragment))) + resolved_path) or '/', params, query, fragment))) def urldefrag(url):