diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-09-27 18:27:02 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-09-27 22:06:32 +0000 |
| commit | a73020f847b3cf8575250569ebefb02573d19224 (patch) | |
| tree | bfa9a6cac9ce924188221904712294b4eeea1fbf /src/net/http/request.go | |
| parent | 36c164ec9c8597ec3507bb4aa9390603e9d29f7a (diff) | |
| download | go-a73020f847b3cf8575250569ebefb02573d19224.tar.xz | |
net/http: add more IDNA2008 tests and fix some omissions
It wasn't lowercasing the string, folding widths, and putting strings
into NFC form. Do those.
Fixes #13835
Change-Id: Ia3de6159417cacec203b48e206e51d79f945df58
Reviewed-on: https://go-review.googlesource.com/29860
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Diffstat (limited to 'src/net/http/request.go')
| -rw-r--r-- | src/net/http/request.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/net/http/request.go b/src/net/http/request.go index bebf55ccc4..a27d13cb98 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -27,6 +27,8 @@ import ( "sync" "golang_org/x/net/idna" + "golang_org/x/text/unicode/norm" + "golang_org/x/text/width" ) const ( @@ -581,6 +583,19 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai return nil } +func idnaASCII(v string) (string, error) { + if isASCII(v) { + return v, nil + } + // The idna package doesn't do everything from + // https://tools.ietf.org/html/rfc5895 so we do it here. + // TODO(bradfitz): should the idna package do this instead? + v = strings.ToLower(v) + v = width.Fold.String(v) + v = norm.NFC.String(v) + return idna.ToASCII(v) +} + // cleanHost cleans up the host sent in request's Host header. // // It both strips anything after '/' or ' ', and puts the value @@ -600,13 +615,13 @@ func cleanHost(in string) string { } host, port, err := net.SplitHostPort(in) if err != nil { // input was just a host - a, err := idna.ToASCII(in) + a, err := idnaASCII(in) if err != nil { return in // garbage in, garbage out } return a } - a, err := idna.ToASCII(host) + a, err := idnaASCII(host) if err != nil { return in // garbage in, garbage out } |
