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: error message for IPv6 addrs with missing port might be improved #4526

Closed
gopherbot opened this issue Dec 11, 2012 · 4 comments

Comments

Projects
None yet
3 participants
@gopherbot
Copy link

commented Dec 11, 2012

by mt4swm:

What steps will reproduce the problem?

See http://play.golang.org/p/gvAUHRN19-

What is the expected output?

I would expect, as the result of net.SplitHostPort("[de:ad:be:ef::ca:fe]"),
the error message "missing port in address ...".

What do you see instead?

"too many colons in address ..."

Which compiler are you using (5g, 6g, 8g, gccgo)?
Which operating system are you using?
Which version are you using?  (run 'go version')
8g, Linux, +835576f9bf0e

Please provide any additional information below.

The modified function below changes the behaviour. After the
test for brackets around host fails, the function also tests
for brackets around hostport now.

func splitHostPort(hostport string) (host, port, zone string, err error) {
    // The port starts after the last colon.
    i := last(hostport, ':')
    if i < 0 {
        err = &AddrError{"missing port in address", hostport}
        return
    }
    host, port = hostport[:i], hostport[i+1:]
    // Can put brackets around host ...
    switch {
    case insideBrackets(host):
        host = host[1 : len(host)-1]
    case insideBrackets(hostport):
        err = &AddrError{"missing port in address", hostport}
    default:
        // ... but if there are no brackets, no colons.
        if byteIndex(host, ':') >= 0 {
            err = &AddrError{"too many colons in address", hostport}
            return
        }
    }
    return
}

func insideBrackets(s string) bool {
    return len(s) > 0 && s[0] == '[' && s[len(s)-1] == ']'
}
@mikioh

This comment has been minimized.

Copy link
Contributor

commented Dec 12, 2012

Comment 1:

Please feel free to push your patch to review process.
<http://golang.org/doc/contribute.html>;
@gopherbot

This comment has been minimized.

Copy link
Author

commented Dec 20, 2012

Comment 2 by mt4swm:

Ok. I'll look into that process soon ...
@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 30, 2012

Comment 3:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jan 30, 2013

Comment 4:

This issue was closed by revision ad34184.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015

@rsc rsc removed the go1.1 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

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.