-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
net/url: "host:port" URLs interpreted as "scheme:opaque" #19779
Comments
related #19297 |
@mattn As I've mentioned, it may be the theoretically correct behavior according to the RFC, but I'm not sure it's the actual behavior developers expect. As such, many people might actually shoot themselves in the foot, just like we did. |
Sorry, there's nothing more we can do here and stay within the go1compat promise. |
I faced similar problem, too: I wonder if it's possible to return error if there's no scheme prefix and can't parse url.Host? Otherwise, developer need to validate raw string them self. |
See rfc3986 section 3.1.
SCHEME can contain dot. So https://play.golang.org/p/sRUFtNKsN- As I mentioned in #19297, please prepend |
Change https://golang.org/cl/81436 mentions this issue: |
That Parse doesn't parse ("foo.com/path" or "foo.com:443/path") has become something of a FAQ. Updates #19779 Updates #21415 Updates #22955 Change-Id: Ib68efddb67f59b1374e8ed94effd4a326988dee7 Reviewed-on: https://go-review.googlesource.com/81436 Reviewed-by: Ian Lance Taylor <[email protected]>
What version of Go are you using (
go version
)?go version go1.8 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/qbW1wWkcKY
What did you expect to see?
I would expect both URLs in the example code to be parsed the same way, and more importantly that the scheme for both is empty (and inherently
IsAbs
returningfalse
for both).What did you see instead?
The hostname in the second url was interpreted as the
scheme
and the port number asopaque
. This causesIsAbs
to returntrue
. This makes IsAbs unsuitable to actually figure out if there's a scheme specified or not in some user input.Although it's debatable whether
example.com
fromexample.com:80
can be interpreted as a scheme, I think it's not the intuitive choice. Alternatively I'd appreciate a way to check for "conventional" scheme's being present without having to so astrings.Contains("://")
manually.The text was updated successfully, but these errors were encountered: