1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:34:40 -07:00

http: use upper case hex in URL escaping

According to RFC 3986: "For consistency, URI producers
and normalizers should use uppercase hexadecimal digits
for all percent-encodings."  Using lower case characters
makes it incompatible with Google APIs when signing OAuth requests.

R=golang-dev, rsc1, rsc
CC=golang-dev
https://golang.org/cl/4352044
This commit is contained in:
Matt Jones 2011-04-04 15:49:49 -04:00 committed by Russ Cox
parent 7d43d00bf5
commit 5fd0a74987
2 changed files with 4 additions and 4 deletions

View File

@ -213,8 +213,8 @@ func urlEscape(s string, mode encoding) string {
j++ j++
case shouldEscape(c, mode): case shouldEscape(c, mode):
t[j] = '%' t[j] = '%'
t[j+1] = "0123456789abcdef"[c>>4] t[j+1] = "0123456789ABCDEF"[c>>4]
t[j+2] = "0123456789abcdef"[c&15] t[j+2] = "0123456789ABCDEF"[c&15]
j += 3 j += 3
default: default:
t[j] = s[i] t[j] = s[i]

View File

@ -490,7 +490,7 @@ var escapeTests = []URLEscapeTest{
}, },
{ {
" ?&=#+%!<>#\"{}|\\^[]`☺\t", " ?&=#+%!<>#\"{}|\\^[]`☺\t",
"+%3f%26%3d%23%2b%25!%3c%3e%23%22%7b%7d%7c%5c%5e%5b%5d%60%e2%98%ba%09", "+%3F%26%3D%23%2B%25!%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%E2%98%BA%09",
nil, nil,
}, },
} }
@ -519,7 +519,7 @@ type UserinfoTest struct {
var userinfoTests = []UserinfoTest{ var userinfoTests = []UserinfoTest{
{"user", "password", "user:password"}, {"user", "password", "user:password"},
{"foo:bar", "~!@#$%^&*()_+{}|[]\\-=`:;'\"<>?,./", {"foo:bar", "~!@#$%^&*()_+{}|[]\\-=`:;'\"<>?,./",
"foo%3abar:~!%40%23$%25%5e&*()_+%7b%7d%7c%5b%5d%5c-=%60%3a;'%22%3c%3e?,.%2f"}, "foo%3Abar:~!%40%23$%25%5E&*()_+%7B%7D%7C%5B%5D%5C-=%60%3A;'%22%3C%3E?,.%2F"},
} }
func TestEscapeUserinfo(t *testing.T) { func TestEscapeUserinfo(t *testing.T) {