You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
URL.with_port doesn't fully validate its argument. It is possible to set a boolean port, a negative port, or a port greater than 65535. Additionally, if the provided port is 0, it is treated as None (i.e. removes the port).
Notably, a bool port or a port out of range will cause an error when trying to retrieve the port:
fromyarlimportURLurl=URL("http://example.com")
true_url=url.with_port(True)
print(true_url.port) # ValueError here
Describe the bug
URL.with_port
doesn't fully validate its argument. It is possible to set a boolean port, a negative port, or a port greater than 65535. Additionally, if the provided port is0
, it is treated asNone
(i.e. removes the port).Notably, a
bool
port or a port out of range will cause an error when trying to retrieve the port:To Reproduce
yarl==1.7.2
Expected behavior
yarl.URL("http://example.com").with_port(True)
raises aTypeError
yarl.URL("http://example.com").with_port(0)
raises aValueError
yarl.URL("http://example.com").with_port(-1)
raises aValueError
yarl.URL("http://example.com").with_port(99999)
raises aValueError
Logs/tracebacks
Output of the code in
To Reproduce
Python Version
CPython 3.9.8
multidict Version
6.0.2
yarl Version
1.7.2
OS
Manjaro Linux
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: