[go] net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

301 views
Skip to first unread message

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 1:22:15 AM1/7/15
to golang-co...@googlegroups.com
Mikio Hara uploaded a change:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This CL allows both Parse and ParseRequestURI functions to parse a
literal IPv6 address followed by a zone identifier within a URI.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 145 insertions(+), 12 deletions(-)



diff --git a/src/net/url/url.go b/src/net/url/url.go
index f167408..2862627 100644
--- a/src/net/url/url.go
+++ b/src/net/url/url.go
@@ -401,10 +401,6 @@
if err != nil {
goto Error
}
- if strings.Contains(url.Host, "%") {
- err = errors.New("hexadecimal escape in host")
- goto Error
- }
}
if url.Path, err = unescape(rest, encodePath); err != nil {
goto Error
@@ -418,26 +414,68 @@
func parseAuthority(authority string) (user *Userinfo, host string, err
error) {
i := strings.LastIndex(authority, "@")
if i < 0 {
- host = authority
- return
+ host, err = parseHost(authority)
+ } else {
+ host, err = parseHost(authority[i+1:])
}
- userinfo, host := authority[:i], authority[i+1:]
+ if err != nil {
+ return nil, "", err
+ }
+ if i < 0 {
+ return nil, host, nil
+ }
+ userinfo := authority[:i]
if strings.Index(userinfo, ":") < 0 {
if userinfo, err = unescape(userinfo, encodeUserPassword); err != nil {
- return
+ return nil, "", err
}
user = User(userinfo)
} else {
username, password := split(userinfo, ":", true)
if username, err = unescape(username, encodeUserPassword); err != nil {
- return
+ return nil, "", err
}
if password, err = unescape(password, encodeUserPassword); err != nil {
- return
+ return nil, "", err
}
user = UserPassword(username, password)
}
- return
+ return user, host, nil
+}
+
+// parseHost parses host as an authority without user information.
+func parseHost(host string) (string, error) {
+ if len(host) == 0 {
+ return host, nil
+ }
+ switch host[0] {
+ case '[': // IP-Literal in RFC 3986, RFC 6874
+ i := strings.Index(host[1:], `]`)
+ if i < 0 {
+ return "", errors.New("missing ']' in host")
+ }
+ j := strings.Index(host[1:1+i], `%25`)
+ switch {
+ case j < 0: // IPv6address in RFC 3986
+ if strings.Contains(host[1:1+i], `%`) {
+ return "", errors.New("hexadecimal escape in host")
+ }
+ default: // IPv6addrz in RFC 6874
+ if strings.Contains(host[1:1+j], `%`) {
+ return "", errors.New("hexadecimal escape in host")
+ }
+ }
+ default: // IPv4address or reg-name in RFC 3986
+ // Note that the reg-name is allowed to use the
+ // percent-encoded form in RFC but we don't use it for
+ // now to avoid messing up with the gap between
+ // allowed characters in URI and allowed characters in
+ // DNS.
+ if strings.Contains(host, `%`) {
+ return "", errors.New("hexadecimal escape in host")
+ }
+ }
+ return host, nil
}

// String reassembles the URL into a valid URL string.
diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go
index d8b19d8..be25cca 100644
--- a/src/net/url/url_test.go
+++ b/src/net/url/url_test.go
@@ -289,6 +289,79 @@
},
"",
},
+ // host and port components of authority
+ {
+ "http://192.168.0.1/",
+ &URL{
+ Scheme: "http",
+ Host: "192.168.0.1",
+ Path: "/",
+ },
+ "",
+ },
+ {
+ "http://192.168.0.1:8080/",
+ &URL{
+ Scheme: "http",
+ Host: "192.168.0.1:8080",
+ Path: "/",
+ },
+ "",
+ },
+ {
+ "http://[fe80::1]/",
+ &URL{
+ Scheme: "http",
+ Host: "[fe80::1]",
+ Path: "/",
+ },
+ "",
+ },
+ {
+ "http://[fe80::1]:8080/",
+ &URL{
+ Scheme: "http",
+ Host: "[fe80::1]:8080",
+ Path: "/",
+ },
+ "",
+ },
+ {
+ "http://[fe80::1%25en0]/",
+ &URL{
+ Scheme: "http",
+ Host: "[fe80::1%25en0]",
+ Path: "/",
+ },
+ "",
+ },
+ {
+ "http://[fe80::1%25en0]:8080/",
+ &URL{
+ Scheme: "http",
+ Host: "[fe80::1%25en0]:8080",
+ Path: "/",
+ },
+ "",
+ },
+ {
+ "http://[fe80::1%25%65%6e%30-._~]/",
+ &URL{
+ Scheme: "http",
+ Host: "[fe80::1%25%65%6e%30-._~]",
+ Path: "/",
+ },
+ "",
+ },
+ {
+ "http://[fe80::1%25%65%6e%30-._~]:8080/",
+ &URL{
+ Scheme: "http",
+ Host: "[fe80::1%25%65%6e%30-._~]:8080",
+ Path: "/",
+ },
+ "",
+ },
}

// more useful string for debugging than fmt's struct printer
@@ -358,9 +431,31 @@
{"/", true},
{pathThatLooksSchemeRelative, true},
{"//not.a.user@%66%6f%6f.com/just/a/path/also", true},
+ {"*", true},
+ {"http://192.168.0.1/", true},
+ {"http://192.168.0.1:8080/", true},
+ {"http://[fe80::1]/", true},
+ {"http://[fe80::1]:8080/", true},
+ {"http://[fe80::1%25en0]/", true},
+ {"http://[fe80::1%25en0]:8080/", true},
+ {"http://[fe80::1%25%65%6e%30-._~]/", true},
+ {"http://[fe80::1%25%65%6e%30-._~]:8080/", true},
+
{"foo.html", false},
{"../dir/", false},
- {"*", true},
+ {"http://192.168.0.%31/", false},
+ {"http://192.168.0.%31:8080/", false},
+ {"http://[fe80::%31]/", false},
+ {"http://[fe80::%31]:8080/", false},
+ {"http://[fe80::%31%25en0]/", false},
+ {"http://[fe80::%31%25en0]:8080/", false},
+
+ // These two cases are valid as textunal representations as
+ // described in RFC 4007, but are not valid as address
+ // literals with IPv6 zone identifiers in URIs as described in
+ // RFC 6874.
+ {"http://[fe80::1%en0]/", false},
+ {"http://[fe80::1%en0]:8080/", false},
}

func TestParseRequestURI(t *testing.T) {

--
https://go-review.googlesource.com/2431

Brad Fitzpatrick (Gerrit)

unread,
Jan 7, 2015, 2:05:07 AM1/7/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 1:

(5 comments)

https://go-review.googlesource.com/#/c/2431/1/src/net/url/url.go
File src/net/url/url.go:

Line 448: if len(host) == 0 {
I think you can drop this and the switch and the default case and just do:

if strings.HasPrefix(host, "[") {
...
}
return host, nil


Line 457: j := strings.Index(host[1:1+i], `%25`)
why you're looking for %25 isn't entirely obvious. some little comments
with example strings might help.

also, why the raw strings? this isn't a regexp, and doesn't have
backslashes.


Line 460: if strings.Contains(host[1:1+i], `%`) {
"%"


Line 463: default: // IPv6addrz in RFC 6874
RFC references are nice, but string literal examples are nice too


Line 464: if strings.Contains(host[1:1+j], `%`) {
"%"


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-HasComments: Yes

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 3:40:31 AM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 1:

(5 comments)

ptal

https://go-review.googlesource.com/#/c/2431/1/src/net/url/url.go
File src/net/url/url.go:

Line 448: if len(host) == 0 {
> I think you can drop this and the switch and the default case and just do:
Done


Line 457: j := strings.Index(host[1:1+i], `%25`)
> why you're looking for %25 isn't entirely obvious. some little comments
> wit
good catch, thanks


Line 460: if strings.Contains(host[1:1+i], `%`) {
> "%"
Done


Line 463: default: // IPv6addrz in RFC 6874
> RFC references are nice, but string literal examples are nice too
Done


Line 464: if strings.Contains(host[1:1+j], `%`) {
> "%"
Done


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: Yes

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 3:42:50 AM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This CL allows both Parse and ParseRequestURI functions to parse a
literal IPv6 address followed by a zone identifier within a URI.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 142 insertions(+), 12 deletions(-)

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 3:59:56 AM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This CL allows both Parse and ParseRequestURI functions to parse a
literal IPv6 address followed by a zone identifier within a URI.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go

Brad Fitzpatrick (Gerrit)

unread,
Jan 7, 2015, 2:03:45 PM1/7/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 3:

(1 comment)

https://go-review.googlesource.com/#/c/2431/3/src/net/url/url.go
File src/net/url/url.go:

Line 451: // E.g., "[fe80::1], "[fe80::1%25en0]"
why is this %25 here? is host already % escape in this function? The
comment on this function should say so. Give a list of example input values
in the comments for this function, above the function, and explain the
escaping level we're in.


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: Yes

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 5:01:12 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 3:

(1 comment)

https://go-review.googlesource.com/#/c/2431/3/src/net/url/url.go
File src/net/url/url.go:

Line 451: // E.g., "[fe80::1], "[fe80::1%25en0]"
> why is this %25 here? is host already % escape in this function? The
> comm
> why is this %25 here?

i don't understand. doesn't rfc6847 describe the reason why we use "%25"
here?

https://tools.ietf.org/html/rfc6874

In a URI, a literal IPv6 address is always embedded between "[" and
"]". This document specifies how a <zone_id> can be appended to the
address. According to URI syntax [RFC3986], "%" is always treated as
an escape character in a URI, so, according to the established URI
syntax [RFC3986] any occurrences of literal "%" symbols in a URI MUST
be percent-encoded and represented in the form "%25". Thus, the
scoped address fe80::a%en1 would appear in a URI as
http://[fe80::a%25en1].

Brad Fitzpatrick (Gerrit)

unread,
Jan 7, 2015, 5:04:47 PM1/7/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 3:

(1 comment)

https://go-review.googlesource.com/#/c/2431/3/src/net/url/url.go
File src/net/url/url.go:

Line 451: // E.g., "[fe80::1], "[fe80::1%25en0]"
> > why is this %25 here?
I don't know any of these RFCs.

I'm reading this code from the perspective of somebody who will come and
read and maintain this code later. Your code needs to be clear and
well-documented.

I honestly didn't know %25 was a standard. I thought that was the net/url
package over-escaping something and you were compensating here.

Makes sense now.

But after line 451, I'd also add:

// (the %25 is the encoding of "%" in a URL; see RFC 6874)

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 8:22:33 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 3:

(1 comment)

ptal

https://go-review.googlesource.com/#/c/2431/3/src/net/url/url.go
File src/net/url/url.go:

Line 451: // E.g., "[fe80::1], "[fe80::1%25en0]"
> I don't know any of these RFCs.
> Your code needs to be clear and well-documented.

yup, thanks for the suggestion. added a comment.

i thought it was crystal clear and you were trying to suggest something
else. (and i have to read it out from between lines.)

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 8:22:48 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This CL allows both Parse and ParseRequestURI functions to parse a
literal IPv6 address followed by a zone identifier within a URI as
described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 147 insertions(+), 12 deletions(-)

Brad Fitzpatrick (Gerrit)

unread,
Jan 7, 2015, 8:30:59 PM1/7/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 4:

(1 comment)

Thanks. This is good after a little wording tweak.

https://go-review.googlesource.com/#/c/2431/4/src/net/url/url.go
File src/net/url/url.go:

Line 454: // IPv6 address textual representation but in URI we
Don't say "we"; it makes it sounds like Go is unique. This applies to
everybody.

// RFC 4007 defines "%" as a delimiter character in
// the textual representation of IPv6 addresses.
// Per RFC 6884, in URIs that "%" is encoded as "%25".


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: Yes

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 8:57:03 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 4:

(1 comment)

https://go-review.googlesource.com/#/c/2431/4/src/net/url/url.go
File src/net/url/url.go:

Line 454: // IPv6 address textual representation but in URI we
> Don't say "we"; it makes it sounds like Go is unique. This applies to
> every
Done

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 8:57:34 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This CL allows both Parse and ParseRequestURI functions to parse a
literal IPv6 address followed by a zone identifier within a URI as
described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 146 insertions(+), 12 deletions(-)

Brad Fitzpatrick (Gerrit)

unread,
Jan 7, 2015, 9:15:22 PM1/7/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 5:

(2 comments)

https://go-review.googlesource.com/#/c/2431/5/src/net/url/url_test.go
File src/net/url/url_test.go:

Line 333: Host: "[fe80::1%25en0]",
we don't unescape the %25 here down to %? I would expect Host to be a
valid literal.


Line 348: "http://[fe80::1%25%65%6e%30-._~]/",
why isn't this an error? What does this mean?


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: Yes

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 11:16:55 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 5:

(1 comment)

https://go-review.googlesource.com/#/c/2431/5/src/net/url/url_test.go
File src/net/url/url_test.go:

Line 333: Host: "[fe80::1%25en0]",
> we don't unescape the %25 here down to %? I would expect Host to be a
> vali
thank you for pushing my back. i was ambivalent on this. will look tonight.
for the present i guess we don't need a exposed function that helps to
escape the host field of http.request, and url.URL.String is enough. does
this work for net/http?

Brad Fitzpatrick (Gerrit)

unread,
Jan 7, 2015, 11:18:45 PM1/7/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 5:

I definitely don't want any new API.

Why does net/http care? What does http need to do differently?

--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: No

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 11:25:05 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 5:

i just wonder what happens if we specify some complicated literal address
to http.Request.Host. the doc says it takes precedence over url.URL.Host.

Brad Fitzpatrick (Gerrit)

unread,
Jan 7, 2015, 11:34:27 PM1/7/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 5:

> i just wonder what happens if we specify some complicated literal
> address to http.Request.Host. the doc says it takes precedence over
> url.URL.Host.

%25 should never appear in any of those. %25 should only ever appear on the
wire, not in Go data structures or APIs.

File bugs against net/http as needed. It's pretty low priority, though.

Mikio Hara (Gerrit)

unread,
Jan 7, 2015, 11:35:58 PM1/7/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 5:

got it

Mikio Hara (Gerrit)

unread,
Jan 8, 2015, 11:52:13 PM1/8/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 5:

(2 comments)

ptal

https://go-review.googlesource.com/#/c/2431/5/src/net/url/url_test.go
File src/net/url/url_test.go:

Line 333: Host: "[fe80::1%25en0]",
> thank you for pushing my back. i was ambivalent on this. will look
> tonight.
Done


Line 348: "http://[fe80::1%25%65%6e%30-._~]/",
> why isn't this an error? What does this mean?
rfc allows pct-encoded+unreserved chars for zone identifiers. also use
cases world be:
- '.' is used for a vlan, sub-interface delimiter
- '-' or '_' is used for a delimiter of logical components; e.g.,
<rack>-<chassis>-<slot>-<physical port>
- '~' is used on windows? perhaps


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: Yes

Mikio Hara (Gerrit)

unread,
Jan 8, 2015, 11:52:34 PM1/8/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This CL allows both Parse and ParseRequestURI functions to parse a
literal IPv6 address followed by a zone identifier within a URI as
described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 166 insertions(+), 13 deletions(-)

Mikio Hara (Gerrit)

unread,
Jan 9, 2015, 1:41:22 AM1/9/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This CL allows Parse, ParseRequestURI functions and String method of URL
to parse/return a literal IPv6 address followed by a zone identifier
within a URI as described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go

Mikio Hara (Gerrit)

unread,
Jan 21, 2015, 5:55:52 AM1/21/15
to Brad Fitzpatrick, golang-co...@googlegroups.com
Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This change allows Parse, ParseRequestURI functions and String method of
URL to parse/return a literal IPv6 address followed by a zone identifier
within a URI as described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 176 insertions(+), 13 deletions(-)

Brad Fitzpatrick (Gerrit)

unread,
Apr 6, 2015, 11:56:38 AM4/6/15
to Mikio Hara, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 10: Code-Review+2 Run-TryBot+1

(5 comments)

Feel free to submit after the following wording tweaks.

https://go-review.googlesource.com/#/c/2431/10/src/net/url/url_test.go
File src/net/url/url_test.go:

Line 292: // host subcomponent; ipv4 address
IPv4 or IPv6 here and elsewhere


Line 332: // host subcomponent; ip-literal; ipv6 address with zone
identifier
Hostname with RFC 6874-encoded IPv6 zone identifier


Line 354: "http://[fe80::1%25%65%6e%301-._~]/", // pct-encoded+unreserved
zone identifier
percent not pct


Line 446: {"http://[fe80::1%25en0]/", true}, // with
alphanum zone identifier
Add comment before this block:

// Tests exercising RFC 6874 compliance:


Line 460: // These two cases are valid as textunal representations as
textual


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: Yes

Gobot Gobot (Gerrit)

unread,
Apr 6, 2015, 11:57:28 AM4/6/15
to Mikio Hara, Brad Fitzpatrick, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 10:

TryBots beginning. Status page: http://farmer.golang.org/try?commit=cbf61179

--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: No

Gobot Gobot (Gerrit)

unread,
Apr 6, 2015, 12:15:45 PM4/6/15
to Mikio Hara, Brad Fitzpatrick, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 10: TryBot-Result+1

TryBots are happy.

Mikio Hara (Gerrit)

unread,
Apr 7, 2015, 5:49:53 AM4/7/15
to Gobot Gobot, Brad Fitzpatrick, golang-co...@googlegroups.com
Reviewers: Gobot Gobot, Brad Fitzpatrick

Mikio Hara uploaded a new patch set:
https://go-review.googlesource.com/2431

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This change allows Parse, ParseRequestURI functions and String method of
URL to parse/return a literal IPv6 address followed by a zone identifier
within a URI as described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 178 insertions(+), 13 deletions(-)

Mikio Hara (Gerrit)

unread,
Apr 7, 2015, 5:50:47 AM4/7/15
to Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Patch Set 10:

(5 comments)

https://go-review.googlesource.com/#/c/2431/10/src/net/url/url_test.go
File src/net/url/url_test.go:

Line 292: // host subcomponent; ipv4 address
> IPv4 or IPv6 here and elsewhere
Done


Line 332: // host subcomponent; ip-literal; ipv6 address with zone
identifier
> Hostname with RFC 6874-encoded IPv6 zone identifier
changed to IPv6 address in RFC 3986 or Pv6 address with zone identifier in
RFC 6847


Line 354: "http://[fe80::1%25%65%6e%301-._~]/", // pct-encoded+unreserved
zone identifier
> percent not pct
Done


Line 446: {"http://[fe80::1%25en0]/", true}, // with
alphanum zone identifier
> Add comment before this block:
Done


Line 460: // These two cases are valid as textunal representations as
> textual
Done


--
https://go-review.googlesource.com/2431
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-HasComments: Yes

Mikio Hara (Gerrit)

unread,
Apr 7, 2015, 10:24:30 AM4/7/15
to golang-...@googlegroups.com, Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com
Mikio Hara has submitted this change and it was merged.

net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs

Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This change allows Parse, ParseRequestURI functions and String method of
URL to parse/return a literal IPv6 address followed by a zone identifier
within a URI as described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
Reviewed-on: https://go-review.googlesource.com/2431
Reviewed-by: Brad Fitzpatrick <brad...@golang.org>
---
M src/net/url/url.go
M src/net/url/url_test.go
2 files changed, 178 insertions(+), 13 deletions(-)

Approvals:
Brad Fitzpatrick: Looks good to me, approved
Reply all
Reply to author
Forward
0 new messages