• Mikio Hara's avatar
    net: don't enclose non-literal IPv6 addresses in square brackets · dc74f51c
    Mikio Hara authored
    The net package uses various textual representations for network
    identifiers and locators on the Internet protocol suite as API.
    In fact, the representations are the composition of subset of multple
    RFCs: RFC 3986, RFC 4007, RFC 4632, RFC 4291 and RFC 5952.
    
    RFC 4007 describes guidelines for the use of textual representation of
    IPv6 addressing/routing scope zone and doesn't prohibit the format for
    implementation dependent purposes, as in, specifying a literal IPv6
    address and its connected region of routing topology as application
    user interface. However, a non-literal IPv6 address, for example, a
    host name, with a zone enclosed in square brackets confuses us because
    a zone is basically for non-global IPv6 addresses and a pair of square
    brackets is used as a set of delimiters between a literal IPv6 address
    and a service name or transport port number.
    
    To mitigate such confusion, this change makes JoinHostPort not enclose
    non-literal IPv6 addresses in square brackets and SplitHostPort accept
    the form "host%zone:port" to recommend that anything enclosed in
    square brackets should be a literal IPv6 address.
    
    Before this change:
    	JoinHostPort("name%zone", "80") = "[name%zone]:80"
    	JoinHostPort("[::1%zone]", "80") = "[::1%zone]:80"
    	SplitHostPort("name%zone:80") = "", "", "address name%zone:80: missing brackets in address"
    	SplitHostPort("[name%zone]:80") = "name%zone", "80", nil
    	SplitHostPort("[::1%zone]:80") = "::1%zone", "80", nil
    
    After this change:
    	JoinHostPort("name%zone", "80") = "name%zone:80"
    	JoinHostPort("[::1%zone]", "80") = "[::1%zone]:80"
    	SplitHostPort("name%zone:80") = "name%zone", "80", nil
    	SplitHostPort("[name%zone]:80") = "name%zone", "80", nil // for backwards compatibility
    	SplitHostPort("[::1%zone]:80") = "::1%zone", "80", nil
    
    Also updates docs and test cases on SplitHostPort and JoinHostPort for
    clarification.
    
    Fixes #18059.
    Fixes #18060.
    
    Change-Id: I5c3ccce4fa0fbdd58f698fc280635ea4a14d2a37
    Reviewed-on: https://go-review.googlesource.com/40510
    Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    dc74f51c
ip_test.go 23.7 KB