diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 297fb4831c16bf..8d9f2793b246d3 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -396,7 +396,6 @@ def test_RFC1808(self): self.checkJoin(RFC1808_BASE, '../../g', 'http://a/g') # "abnormal" cases from RFC 1808: - self.checkJoin(RFC1808_BASE, '', 'http://a/b/c/d;p?q#f') self.checkJoin(RFC1808_BASE, 'g.', 'http://a/b/c/g.') self.checkJoin(RFC1808_BASE, '.g', 'http://a/b/c/.g') self.checkJoin(RFC1808_BASE, 'g..', 'http://a/b/c/g..') @@ -412,6 +411,7 @@ def test_RFC1808(self): #self.checkJoin(RFC1808_BASE, 'http:', 'http:') # XXX: The following tests are no longer compatible with RFC3986 + # self.checkJoin(RFC1808_BASE, '', 'http://a/b/c/d;p?q#f') # self.checkJoin(RFC1808_BASE, '../../../g', 'http://a/../g') # self.checkJoin(RFC1808_BASE, '../../../../g', 'http://a/../../g') # self.checkJoin(RFC1808_BASE, '/./g', 'http://a/./g') @@ -577,7 +577,7 @@ def test_urljoins(self): self.checkJoin('a', 'b', 'b') # Test with empty (but defined) components. - self.checkJoin(RFC1808_BASE, '', 'http://a/b/c/d;p?q#f') + self.checkJoin(RFC1808_BASE, '', 'http://a/b/c/d;p?q') self.checkJoin(RFC1808_BASE, '#', 'http://a/b/c/d;p?q#', relroundtrip=False) self.checkJoin(RFC1808_BASE, '#z', 'http://a/b/c/d;p?q#z') self.checkJoin(RFC1808_BASE, '?', 'http://a/b/c/d;p?', relroundtrip=False) @@ -588,7 +588,7 @@ def test_urljoins(self): self.checkJoin(RFC1808_BASE, ';#z', 'http://a/b/c/;#z') self.checkJoin(RFC1808_BASE, ';x', 'http://a/b/c/;x') self.checkJoin(RFC1808_BASE, '/w', 'http://a/w') - self.checkJoin(RFC1808_BASE, '//', 'http://a/b/c/d;p?q#f') + self.checkJoin(RFC1808_BASE, '//', 'http://a/b/c/d;p?q') self.checkJoin(RFC1808_BASE, '//#z', 'http://a/b/c/d;p?q#z') self.checkJoin(RFC1808_BASE, '//?y', 'http://a/b/c/d;p?y') self.checkJoin(RFC1808_BASE, '//;x', 'http://;x') @@ -597,7 +597,7 @@ def test_urljoins(self): # For backward compatibility with RFC1630, the scheme name is allowed # to be present in a relative reference if it is the same as the base # URI scheme. - self.checkJoin(RFC1808_BASE, 'http:', 'http://a/b/c/d;p?q#f') + self.checkJoin(RFC1808_BASE, 'http:', 'http://a/b/c/d;p?q') self.checkJoin(RFC1808_BASE, 'http:#', 'http://a/b/c/d;p?q#', relroundtrip=False) self.checkJoin(RFC1808_BASE, 'http:#z', 'http://a/b/c/d;p?q#z') self.checkJoin(RFC1808_BASE, 'http:?', 'http://a/b/c/d;p?', relroundtrip=False) @@ -608,7 +608,7 @@ def test_urljoins(self): self.checkJoin(RFC1808_BASE, 'http:;#z', 'http://a/b/c/;#z') self.checkJoin(RFC1808_BASE, 'http:;x', 'http://a/b/c/;x') self.checkJoin(RFC1808_BASE, 'http:/w', 'http://a/w') - self.checkJoin(RFC1808_BASE, 'http://', 'http://a/b/c/d;p?q#f') + self.checkJoin(RFC1808_BASE, 'http://', 'http://a/b/c/d;p?q') self.checkJoin(RFC1808_BASE, 'http://#z', 'http://a/b/c/d;p?q#z') self.checkJoin(RFC1808_BASE, 'http://?y', 'http://a/b/c/d;p?y') self.checkJoin(RFC1808_BASE, 'http://;x', 'http://;x') diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index a721d777c82f82..d7640fa62ba9e8 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -566,8 +566,6 @@ def urljoin(base, url, allow_fragments=True): interpretation of the latter.""" if not base: return url - if not url: - return base base, url, _coerce_result = _coerce_args(base, url) bscheme, bnetloc, bpath, bquery, bfragment = \ @@ -589,8 +587,6 @@ def urljoin(base, url, allow_fragments=True): path = bpath if query is None: query = bquery - if fragment is None: - fragment = bfragment return _coerce_result(_urlunsplit(scheme, netloc, path, query, fragment)) diff --git a/Misc/NEWS.d/next/Library/2020-02-29-20-44-36.bpo-39799.qTHOaP.rst b/Misc/NEWS.d/next/Library/2020-02-29-20-44-36.bpo-39799.qTHOaP.rst new file mode 100644 index 00000000000000..a5c12228ff1f8f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-02-29-20-44-36.bpo-39799.qTHOaP.rst @@ -0,0 +1 @@ +The fragment of the base URI is now always discarded in :func:`urllib.parse.urljoin` in accordance to :rfc:`3986`.