urllib: Simplify splithost by calling into urlparse. (#1849) · AmitKumar79/PythonBegin@90e01e5 · GitHub
Skip to content

Commit 90e01e5

Browse files
postmastersvstinner
authored andcommitted
urllib: Simplify splithost by calling into urlparse. (#1849)
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``.
1 parent 5cc7ac2 commit 90e01e5

4 files changed

Lines changed: 47 additions & 14 deletions

File tree

Lib/test/test_urlparse.py

Lines changed: 39 additions & 12 deletions

Lib/urllib/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ def splithost(url):
947947
"""splithost('//host[:port]/path') --> 'host[:port]', '/path'."""
948948
global _hostprog
949949
if _hostprog is None:
950-
_hostprog = re.compile('//([^/?]*)(.*)', re.DOTALL)
950+
_hostprog = re.compile('//([^/#?]*)(.*)', re.DOTALL)
951951

952952
match = _hostprog.match(url)
953953
if match:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ Max Neunhöffer
10911091
Anthon van der Neut
10921092
George Neville-Neil
10931093
Hieu Nguyen
1094+
Nam Nguyen
10941095
Johannes Nicolai
10951096
Samuel Nicolary
10961097
Jonathan Niehof

Misc/NEWS

Lines changed: 6 additions & 1 deletion

0 commit comments

Comments
 (0)