[issue43871] urllib.parse.urlparse doesn't check port

2021-05-01 Thread Miguel Brito


Miguel Brito  added the comment:

I also think the validation logic should be ran as early as possible.

I gave it a shot and implemented it. 

I appreciate any reviews: https://github.com/python/cpython/pull/25774

Got some ideas from https://github.com/python/cpython/pull/16780

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43871] urllib.parse.urlparse doesn't check port

2021-05-01 Thread Miguel Brito


Change by Miguel Brito :


--
keywords: +patch
nosy: +miguendes
nosy_count: 4.0 -> 5.0
pull_requests: +24464
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25774

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43871] urllib.parse.urlparse doesn't check port

2021-04-17 Thread Alexei Pastuchov


Alexei Pastuchov  added the comment:

Thank you for your swift response and your willingness to add port validation 
to _checknetloc.

I think the validation itself should compound both exceptional branches 
implemented in port[3]
* port is an int
* port is in the range

[3] 
https://github.com/python/cpython/blob/e1903e11a3d42512effe336026e0c67f602e5848/Lib/urllib/parse.py#L173-L178

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43871] urllib.parse.urlparse doesn't check port

2021-04-17 Thread Senthil Kumaran


Change by Senthil Kumaran :


--
assignee:  -> orsenthil
versions: +Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43871] urllib.parse.urlparse doesn't check port

2021-04-17 Thread Senthil Kumaran


Senthil Kumaran  added the comment:

Treating this as bug in itself might be a better idea than waiting for a ipv6 
scope introduction, which had few caveats. 

> Would it be an improvement if _checknetloc[2] validates the value of port 
> properly?

Yes, we could check if it is an int. That should be sufficient.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43871] urllib.parse.urlparse doesn't check port

2021-04-16 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

I guess moving port validation logic to parsing time is done as part of 
https://github.com/python/cpython/pull/16780

--
nosy: +orsenthil, vstinner, xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43871] urllib.parse.urlparse doesn't check port

2021-04-16 Thread Alexei Pastuchov


New submission from Alexei Pastuchov :

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 "", line 1, in 
  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com