[New-bugs-announce] [issue43871] urllib.parse.urlparse doesn't check port

Alexei Pastuchov report at bugs.python.org
Fri Apr 16 13:30:08 EDT 2021


New submission from Alexei Pastuchov <info at maximka.de>:

It is possible to get valid ParseResult from the urlparse function even for a non-numeric port value. Only by requesting the port it fails[1].
Would it be an improvement if _checknetloc[2] validates the value of port properly?


// code snippet
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.parse import urlparse
>>> uri = 'xx://foo:bar'
>>> uri_parts = urlparse(uri)
>>> uri_parts.netloc
'foo:bar'
>>> uri_parts.port
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/urllib/parse.py", line 174, in port
    raise ValueError(message) from None
ValueError: Port could not be cast to integer value as 'bar'
// code snippet

[1] https://github.com/python/cpython/blob/e1903e11a3d42512effe336026e0c67f602e5848/Lib/urllib/parse.py#L172
[2] https://github.com/python/cpython/blob/e1903e11a3d42512effe336026e0c67f602e5848/Lib/urllib/parse.py#L416

----------
messages: 391238
nosy: palik
priority: normal
severity: normal
status: open
title: urllib.parse.urlparse doesn't check port

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43871>
_______________________________________


More information about the New-bugs-announce mailing list