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

Comments

Projects
None yet
3 participants
@mikioh
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2016

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

@kavirajk

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2016

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

@gopherbot

This comment has been minimized.

Copy link

commented Apr 13, 2017

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

@gopherbot gopherbot closed this in dc74f51 Apr 14, 2017

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

net, doc: document JoinHostPort change in release notes, clarify its …
…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.
You can’t perform that action at this time.