diff options
author | Russ Cox <rsc@golang.org> | 2016-01-23 23:31:23 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2016-01-26 16:24:06 +0000 |
commit | 038b8139433054c70f17494f4cd96dd4f3ddd696 (patch) | |
tree | 3838f424703953d7284efe64d2064c11c521c1e9 | |
parent | 980364b7a2425657a5c66dcad4e52f6cd3723a77 (diff) | |
download | go-038b8139433054c70f17494f4cd96dd4f3ddd696.tar.gz go-038b8139433054c70f17494f4cd96dd4f3ddd696.zip |
net/url: allow spaces in IPv6 zone identifier for Windows
Windows: putting spaces where they don't belong since Windows NT 3.1.
Fixes #14002.
Change-Id: I48ba8a7bfe3f27f83c8aa8355a8d355933d6c5df
Reviewed-on: https://go-review.googlesource.com/18855
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r-- | src/net/url/url.go | 3 | ||||
-rw-r--r-- | src/net/url/url_test.go | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/net/url/url.go b/src/net/url/url.go index 3ea75637ac..1a93e3496e 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -193,8 +193,9 @@ func unescape(s string, mode encoding) (string, error) { // that are valid host name bytes in their unescaped form. // That is, you can use escaping in the zone identifier but not // to introduce bytes you couldn't just write directly. + // But Windows puts spaces here! Yay. v := unhex(s[i+1])<<4 | unhex(s[i+2]) - if s[i:i+3] != "%25" && shouldEscape(v, encodeHost) { + if s[i:i+3] != "%25" && v != ' ' && shouldEscape(v, encodeHost) { return "", EscapeError(s[i : i+3]) } } diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index c31b18980e..d3f8487bd7 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -531,6 +531,17 @@ var urltests = []URLTest{ }, "", }, + // spaces in hosts are disallowed but escaped spaces in IPv6 scope IDs are grudgingly OK. + // This happens on Windows. + // golang.org/issue/14002 + { + "tcp://[2020::2020:20:2020:2020%25Windows%20Loves%20Spaces]:2020", + &URL{ + Scheme: "tcp", + Host: "[2020::2020:20:2020:2020%Windows Loves Spaces]:2020", + }, + "", + }, } // more useful string for debugging than fmt's struct printer |