diff -r 9a840524929b Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py Mon Aug 11 07:03:05 2014 -0700 +++ b/Lib/test/test_urlparse.py Tue Aug 26 10:58:23 2014 -0700 @@ -380,6 +380,9 @@ # 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') + def test_RFC2732(self): str_cases = [ ('http://Test.python.org:5432/foo/', 'test.python.org', 5432), diff -r 9a840524929b Lib/urllib/parse.py --- a/Lib/urllib/parse.py Mon Aug 11 07:03:05 2014 -0700 +++ b/Lib/urllib/parse.py Tue Aug 26 10:58:23 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() @@ -463,9 +467,9 @@ # do some post-processing here. if the last segment was a relative dir, # then we need to append the trailing '/' resolved_path.append('') - + return _coerce_result(urlunparse((scheme, netloc, '/'.join( - resolved_path), params, query, fragment))) + resolved_path) or '/', params, query, fragment))) def urldefrag(url):