-
Notifications
You must be signed in to change notification settings - Fork 346
Calling port()
with a default port returns None unexpectedly
#957
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I would think the docs are pretty clear on this issue. https://docs.rs/url/2.5.2/url/struct.Url.html#method.port You want Note that changing the behaviour of port is a breaking change, and not something we'd consider doing at the moment. |
Can you add another API that returns I need to distinguish between these cases because when user scans a QR code, in the first case this is likely an HTTPS proxy URL and in the second case it is likely a normal URL that I want to offer to open in a browser: As a workaround I will now try to look at |
Another way to fix this would be to add an option to |
As a workaround I now replace |
Sorry about the really late reply. I think when I was looking originally, the examples in my editor got truncated like this |
In my case I want to know if the port is there or not, i.e. distinguish between |
We just ran into this problem too. In particular, we want to use the port the user specified, buy only if it is specified, otherwise default to our own choice of port (e.g. |
@emilk We replace scheme before parsing as a workaround: |
I think this issues can be closed actually. If you don't like that If you want to distinguish between the Because now this issue is hijacked by people who want the second thing. This is not what the original issue is about. |
Yeah that makes sense. Given that this is attempting to follow the standard, which doesn't distinguish, I think it's unlikely we'll add additional tracking for this. Not strongly opposed to it, but it seems unlikely. Worth looking at what it might look like as an implementation. |
Describe the bug
related to #28
This was an issue way back in 2014, but doesn't seem like it was ever really addressed.
I would expect calling
port()
onhttp://example.com
to return 80. It is really confusing that it would return a None. It's even worse when you set the port explicitlyhttp://example.com:80
and it still seems like it isn't working correctly because it still returns None.I could update the docs to have an example of the port being ignored, but it seems like it would just make more sense to have
port()
actually return the port and do what is suggested in this commentThe text was updated successfully, but these errors were encountered: