summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-06-20 14:20:36 (GMT)
committerGitHub <noreply@github.com>2017-06-20 14:20:36 (GMT)
commitd4324baca4c03eb8d55446cd1b74b32ec5633af5 (patch)
tree4144e9fae2d0d6913340f9c0ff9c96612abd0f26 /Lib/test/test_urllib.py
parentb39a7481ee7e6166d6d2b252a7a514b1f6553dfa (diff)
downloadcpython-d4324baca4c03eb8d55446cd1b74b32ec5633af5.zip
cpython-d4324baca4c03eb8d55446cd1b74b32ec5633af5.tar.gz
cpython-d4324baca4c03eb8d55446cd1b74b32ec5633af5.tar.bz2
bpo-30500: urllib: Simplify splithost by calling into urlparse. (#1849) (#2294)
The current regex based splitting produces a wrong result. For example:: http://abc#@def Web browsers parse that URL as ``http://abc/#@def``, that is, the host is ``abc``, the path is ``/``, and the fragment is ``#@def``. (cherry picked from commit 90e01e50ef8a9e6c91f30d965563c378a4ad26de)
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r--Lib/test/test_urllib.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 14de91e..1ce9201 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -879,6 +879,26 @@ class Utility_Tests(unittest.TestCase):
self.assertEqual(splithost('/foo/bar/baz.html'),
(None, '/foo/bar/baz.html'))
+ # bpo-30500: # starts a fragment.
+ self.assertEqual(splithost('//127.0.0.1#@host.com'),
+ ('127.0.0.1', '/#@host.com'))
+ self.assertEqual(splithost('//127.0.0.1#@host.com:80'),
+ ('127.0.0.1', '/#@host.com:80'))
+ self.assertEqual(splithost('//127.0.0.1:80#@host.com'),
+ ('127.0.0.1:80', '/#@host.com'))
+
+ # Empty host is returned as empty string.
+ self.assertEqual(splithost("///file"),
+ ('', '/file'))
+
+ # Trailing semicolon, question mark and hash symbol are kept.
+ self.assertEqual(splithost("//example.net/file;"),
+ ('example.net', '/file;'))
+ self.assertEqual(splithost("//example.net/file?"),
+ ('example.net', '/file?'))
+ self.assertEqual(splithost("//example.net/file#"),
+ ('example.net', '/file#'))
+
def test_splituser(self):
splituser = urllib.splituser
self.assertEqual(splituser('User:Pass@www.python.org:080'),