This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author palik
Recipients palik
Date 2021-04-16.17:30:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618594208.69.0.606171015487.issue43871@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-04-16 17:30:08paliksetrecipients: + palik
2021-04-16 17:30:08paliksetmessageid: <1618594208.69.0.606171015487.issue43871@roundup.psfhosted.org>
2021-04-16 17:30:08paliklinkissue43871 messages
2021-04-16 17:30:08palikcreate