diff -r f1c6e7f86bbc Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py Fri Sep 27 22:14:31 2013 +0300 +++ b/Lib/test/test_urlparse.py Tue Oct 01 22:00:18 2013 +0800 @@ -679,6 +679,20 @@ urllib.parse.urljoin("http://python.org", b"http://python.org") with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urljoin(b"http://python.org", "http://python.org") + # issue 19094 + self.assertRaises(TypeError, urllib.parse.urljoin, + "http://python.org", b"") + self.assertRaises(TypeError, urllib.parse.urljoin, + b"http://python.org", "") + self.assertRaises(TypeError, urllib.parse.urljoin, + "http://python.org", []) + self.assertRaises(TypeError, urllib.parse.urljoin, + b"http://python.org", []) + self.assertRaises(TypeError, urllib.parse.urljoin, + bytearray(b"http://python.org"), []) + self.assertRaises(TypeError, urllib.parse.urljoin, + ["http://python.org"], []) + self.assertRaises(TypeError, urllib.parse.urljoin, [], []) def _check_result_type(self, str_type): num_args = len(str_type._fields) diff -r f1c6e7f86bbc Lib/urllib/parse.py --- a/Lib/urllib/parse.py Fri Sep 27 22:14:31 2013 +0300 +++ b/Lib/urllib/parse.py Tue Oct 01 22:00:18 2013 +0800 @@ -405,10 +405,12 @@ def urljoin(base, url, allow_fragments=True): """Join a base URL and a possibly relative URL to form an absolute interpretation of the latter.""" - if not base: - return url - if not url: - return base + if not all(type(resource) in (str, bytes, bytearray) for resource in (base, +url)): + raise TypeError("The first and second arguments must be str or " + "bytes instances") + if not base or not url: + return base + url base, url, _coerce_result = _coerce_args(base, url) bscheme, bnetloc, bpath, bparams, bquery, bfragment = \ urlparse(base, '', allow_fragments)