mirror of
https://github.com/golang/go
synced 2024-11-23 20:10:08 -07:00
Revert "net/url: escape URL.RawQuery on Parse if it contains invalid characters"
This reverts commit CL 99135 (git rev 1040626c0c
).
Reason for revert: breaks valid code; see #27302
Fixes #27302
Updates #22907
Change-Id: I82bb0c28ae1683140c71e7a2224c4ded3f4acea1
Reviewed-on: https://go-review.googlesource.com/137716
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
541f9c0345
commit
b50210f571
@ -534,13 +534,7 @@ func parse(rawurl string, viaRequest bool) (*URL, error) {
|
||||
url.ForceQuery = true
|
||||
rest = rest[:len(rest)-1]
|
||||
} else {
|
||||
var q string
|
||||
rest, q = split(rest, "?", true)
|
||||
if validQuery(q) {
|
||||
url.RawQuery = q
|
||||
} else {
|
||||
url.RawQuery = QueryEscape(q)
|
||||
}
|
||||
rest, url.RawQuery = split(rest, "?", true)
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(rest, "/") {
|
||||
@ -1139,46 +1133,3 @@ func validUserinfo(s string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// validQuery reports whether s is a valid query string per RFC 3986
|
||||
// Section 3.4:
|
||||
// query = *( pchar / "/" / "?" )
|
||||
// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
// / "*" / "+" / "," / ";" / "="
|
||||
func validQuery(s string) bool {
|
||||
pctEnc := 0
|
||||
|
||||
for _, r := range s {
|
||||
if pctEnc > 0 {
|
||||
if uint32(r) > 255 || !ishex(byte(r)) {
|
||||
return false
|
||||
}
|
||||
pctEnc--
|
||||
continue
|
||||
} else if r == '%' {
|
||||
pctEnc = 2
|
||||
continue
|
||||
}
|
||||
|
||||
if 'A' <= r && r <= 'Z' {
|
||||
continue
|
||||
}
|
||||
if 'a' <= r && r <= 'z' {
|
||||
continue
|
||||
}
|
||||
if '0' <= r && r <= '9' {
|
||||
continue
|
||||
}
|
||||
switch r {
|
||||
case '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')',
|
||||
'*', '+', ',', ';', '=', ':', '@', '/', '?':
|
||||
continue
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
@ -590,16 +590,6 @@ var urltests = []URLTest{
|
||||
},
|
||||
"mailto:?subject=hi",
|
||||
},
|
||||
{
|
||||
"https://example.com/search?q=Фотки собак&source=lnms",
|
||||
&URL{
|
||||
Scheme: "https",
|
||||
Host: "example.com",
|
||||
Path: "/search",
|
||||
RawQuery: "q%3D%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA%26source%3Dlnms",
|
||||
},
|
||||
"https://example.com/search?q%3D%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA%26source%3Dlnms",
|
||||
},
|
||||
}
|
||||
|
||||
// more useful string for debugging than fmt's struct printer
|
||||
@ -1449,7 +1439,6 @@ func TestParseErrors(t *testing.T) {
|
||||
{"cache_object:foo", true},
|
||||
{"cache_object:foo/bar", true},
|
||||
{"cache_object/:foo/bar", false},
|
||||
{"https://example.com/search?q=Фотки собак&source=lnms", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
u, err := Parse(tt.in)
|
||||
|
Loading…
Reference in New Issue
Block a user