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: JoinHostPort should not enclose non-IP literals in square brackets #18059

Closed
mikioh opened this issue Nov 27, 2016 · 3 comments
Closed

net: JoinHostPort should not enclose non-IP literals in square brackets #18059

mikioh opened this issue Nov 27, 2016 · 3 comments
Milestone

Comments

@mikioh
Copy link
Contributor

mikioh commented Nov 27, 2016

Looks like I forgot to add a test case. As per https://tools.ietf.org/html/rfc4007 (and considering https://tools.ietf.org/html/rfc6874 for the interoperability of the output of JoinHostPort), JoinHostPort should not enclose any non-IP literal in square brackets, and remove any scope zone identifier if necessary for avoiding ambiguity.

For example,

package main

import (
	"fmt"
	"net"
)

func main() {
	// /etc/hosts should have an entry mapping "locahost" to "::1".
	for _, host := range []string{"localhost", "::1", "::1%lo0", "localhost%lo0"} {
		fmt.Println(net.JoinHostPort(host, ""))
	}

	// Output:
	// localhost:
	// [::1]:
	// [::1%lo0]:
	// localhost: not [localhost%lo0]:
}
@kavirajk
Copy link
Contributor

@mikioh Sorry this may sound stupid. How do we identify non-IP literal? both "::1%lo0", "localhost%lo0" seems to be invalid.

@kavirajk
Copy link
Contributor

@mikioh got it. "localhost" is not a valid ipv6 address.

@gopherbot
Copy link

CL https://golang.org/cl/40510 mentions this issue.

gopherbot pushed a commit that referenced this issue Jun 14, 2017
…docs

Updates #18059
Updates #20587

Change-Id: Icbb4c7cb201ac51d2cc6066620b47ba09ff6fe65
Reviewed-on: https://go-review.googlesource.com/45780
Reviewed-by: Chris Broadfoot <cbro@golang.org>
@golang golang locked and limited conversation to collaborators Apr 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants