aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/http.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-10-21 11:43:12 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-10-21 21:44:16 +0000
commit6ca662ca0e1a41077bd93501a5d04668474bca69 (patch)
tree5ff7bc01e7b3c6b493a56876f40c7ec622f407b5 /src/net/http/http.go
parente64e858c51bc7739a308fa0749ded1123da2e89c (diff)
downloadgo-6ca662ca0e1a41077bd93501a5d04668474bca69.tar.xz
net/http: make Redirect escape non-ASCII in Location header
Only ASCII is permitted there. Fixes #4385 Change-Id: I63708b04a041cdada0fdfc1f2308fcb66889a27b Reviewed-on: https://go-review.googlesource.com/31732 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http/http.go')
-rw-r--r--src/net/http/http.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/net/http/http.go b/src/net/http/http.go
index b2130b11a8..7e0b77506b 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -5,6 +5,7 @@
package http
import (
+ "strconv"
"strings"
"time"
"unicode/utf8"
@@ -56,3 +57,27 @@ func isASCII(s string) bool {
}
return true
}
+
+func hexEscapeNonASCII(s string) string {
+ newLen := 0
+ for i := 0; i < len(s); i++ {
+ if s[i] >= utf8.RuneSelf {
+ newLen += 3
+ } else {
+ newLen++
+ }
+ }
+ if newLen == len(s) {
+ return s
+ }
+ b := make([]byte, 0, newLen)
+ for i := 0; i < len(s); i++ {
+ if s[i] >= utf8.RuneSelf {
+ b = append(b, '%')
+ b = strconv.AppendInt(b, int64(s[i]), 16)
+ } else {
+ b = append(b, s[i])
+ }
+ }
+ return string(b)
+}