New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Url type port limit not checked #1654
Comments
Is there a nice RFC explicitly stating a limit for port? If so I guess we could add a check, but this is not a bug, just a limit of the current validation. You can implement a much cleaner validator: class Test(BaseModel):
url: stricturl(allowed_schemes=['tcp'])
@validator('url')
def validate_port(cls, v):
if int(v.port) > 2**16:
raise ValueError('port overflow')
return v |
Hi, Your validator will fail if port is missing, with tcp protocol that doesn't really make sense but with http(s) protocol is does:
class Test(BaseModel):
url: stricturl(allowed_schemes=['tcp'])
@validator('url')
def validate_port(cls, v):
if v.port is None:
return v
elif int(v.port) > 2**16:
raise ValueError('port overflow')
return v (the tcp protocol is a bad showcase about default port) |
Good point,
PR welcome to add this check to all URL validation, I know technically it's a breaking chance, but I think a reasonable one, given that a higher port is invalid anyway. |
the port 0 is tagged as reserved and should not be usable as such since most routers will reject it. I'll work on a PR within a few days (this weekend I hope if I have time) |
makes sense to allow 0, also makes the check easier.
Thanks so much |
I'm currently working on a PR, Should I open news issues for each or asking here is fine ? |
Would it make sense to separate |
|
Hi,
The port limit is not checked by URLs types:
Excepted result: raise an error,
my current workaround
The text was updated successfully, but these errors were encountered: