net: SplitHostPort has inconsistent error conditions #18040
Closed
Labels
Comments
I think it's pretty consistent: if there's no colon, it returns an error: https://play.golang.org/p/77zhzVOa9g In any case, we've had this same behavior for 4+ years now, so I don't think we want to change it now. The new URL.Port and URL.Hostname methods in Go 1.8 should help with this, though, since I think they're more likely doing what you want. |
I think the ":80" shouldn't be an error as it's has well-defined
meaning ((for listen) all interfaces, or (for dial) localhost.)
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In net.SplitHostPort, giving a string with a port defined, but no hostname (e.g. ":80"), results in an empty host, a port and an empty error. Providing a hostname (or IP) with no port (e.g. "foo.bar.com"), results in an error.
I would think that both of these scenarios should behave in the same way: either both should return an error, or both should return an empty value and no error.
https://play.golang.org/p/-qKy6sik52
The text was updated successfully, but these errors were encountered: