Commit a967f57d authored by Russ Cox's avatar Russ Cox

http.URLEscape: escape all bytes required by RFC 2396

Fixes #125.

R=r
https://golang.org/cl/154143
parent 2a6bb2c6
...@@ -52,14 +52,16 @@ func (e URLEscapeError) String() string { ...@@ -52,14 +52,16 @@ func (e URLEscapeError) String() string {
return "invalid URL escape " + strconv.Quote(string(e)) return "invalid URL escape " + strconv.Quote(string(e))
} }
// Return true if the specified character should be escaped when appearing in a // Return true if the specified character should be escaped when
// URL string. // appearing in a URL string, according to RFC 2396.
//
// TODO: for now, this is a hack; it only flags a few common characters that have
// special meaning in URLs. That will get the job done in the common cases.
func shouldEscape(c byte) bool { func shouldEscape(c byte) bool {
if c <= ' ' || c >= 0x7F {
return true
}
switch c { switch c {
case ' ', '?', '&', '=', '#', '+', '%': case '<', '>', '#', '%', '"', // RFC 2396 delims
'{', '}', '|', '\\', '^', '[', ']', '`', // RFC2396 unwise
'?', '&', '=', '+': // RFC 2396 reserved in path
return true return true
} }
return false; return false;
......
...@@ -335,8 +335,8 @@ var escapeTests = []URLEscapeTest{ ...@@ -335,8 +335,8 @@ var escapeTests = []URLEscapeTest{
nil, nil,
}, },
URLEscapeTest{ URLEscapeTest{
" ?&=#+%!", " ?&=#+%!<>#\"{}|\\^[]`☺\t",
"+%3f%26%3d%23%2b%25!", "+%3f%26%3d%23%2b%25!%3c%3e%23%22%7b%7d%7c%5c%5e%5b%5d%60%e2%98%ba%09",
nil, nil,
}, },
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment