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

mikioh opened this issue Nov 27, 2016 · 3 comments


None yet
3 participants
Copy link

commented Nov 27, 2016

Looks like I forgot to add a test case. As per (and considering 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 (

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]:

This comment has been minimized.

Copy link

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.


This comment has been minimized.

Copy link

commented Nov 29, 2016

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


This comment has been minimized.

Copy link

commented Apr 13, 2017

CL 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 …

Updates #18059
Updates #20587

Change-Id: Icbb4c7cb201ac51d2cc6066620b47ba09ff6fe65
Reviewed-by: Chris Broadfoot <>

@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.