Skip to content
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: SplitHostPort has inconsistent error conditions #18040

Closed
adamhassel opened this issue Nov 24, 2016 · 2 comments

Comments

Projects
None yet
4 participants
@adamhassel
Copy link

commented Nov 24, 2016

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

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 24, 2016

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.

@bradfitz bradfitz closed this Nov 24, 2016

@minux

This comment has been minimized.

Copy link
Member

commented Nov 24, 2016

@golang golang locked and limited conversation to collaborators Nov 24, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.