Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23e3856

Browse files
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.
1 parent 7b9cb25 commit 23e3856

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

Lib/test/test_urlparse.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
RFC1808_BASE = "http://a/b/c/d;p?q#f"
88
RFC2396_BASE = "http://a/b/c/d;p?q"
9+
RFC3986_BASE = "http://a/b/c/d;p?q"
910

1011
class UrlParseTestCase(unittest.TestCase):
1112

@@ -167,8 +168,6 @@ def test_RFC1808(self):
167168
def test_RFC2396(self):
168169
# cases from RFC 2396
169170

170-
self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y')
171-
self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
172171

173172
self.checkJoin(RFC2396_BASE, 'g:h', 'g:h')
174173
self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g')
@@ -210,6 +209,14 @@ def test_RFC2396(self):
210209
self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x')
211210
self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x')
212211

212+
#The following scenarios have been updated in RFC3986
213+
#self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y')
214+
#self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
215+
216+
def test_RFC3986(self):
217+
self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
218+
self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
219+
213220
def test_urldefrag(self):
214221
for url, defrag, frag in [
215222
('http://python.org#frag', 'http://python.org', 'frag'),

Lib/urllib/parse.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,18 @@ def urljoin(base, url, allow_fragments=True):
219219
if path[:1] == '/':
220220
return urlunparse((scheme, netloc, path,
221221
params, query, fragment))
222-
if not (path or params or query):
223-
return urlunparse((scheme, netloc, bpath,
224-
bparams, bquery, fragment))
222+
if not path:
223+
path = bpath
224+
if not params:
225+
params = bparams
226+
else:
227+
path = path[:-1]
228+
return urlunparse((scheme, netloc, path,
229+
params, query, fragment))
230+
if not query:
231+
query = bquery
232+
return urlunparse((scheme, netloc, path,
233+
params, query, fragment))
225234
segments = bpath.split('/')[:-1] + path.split('/')
226235
# XXX The stuff below is bogus in various ways...
227236
if segments[-1] == '.':

0 commit comments

Comments
 (0)