Skip to content

Commit b50210f

Browse files
committed
Revert "net/url: escape URL.RawQuery on Parse if it contains invalid characters"
This reverts commit CL 99135 (git rev 1040626). 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 <[email protected]>
1 parent 541f9c0 commit b50210f

File tree

2 files changed

+1
-61
lines changed

2 files changed

+1
-61
lines changed

src/net/url/url.go

+1-50
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,7 @@ func parse(rawurl string, viaRequest bool) (*URL, error) {
534534
url.ForceQuery = true
535535
rest = rest[:len(rest)-1]
536536
} else {
537-
var q string
538-
rest, q = split(rest, "?", true)
539-
if validQuery(q) {
540-
url.RawQuery = q
541-
} else {
542-
url.RawQuery = QueryEscape(q)
543-
}
537+
rest, url.RawQuery = split(rest, "?", true)
544538
}
545539

546540
if !strings.HasPrefix(rest, "/") {
@@ -1139,46 +1133,3 @@ func validUserinfo(s string) bool {
11391133
}
11401134
return true
11411135
}
1142-
1143-
// validQuery reports whether s is a valid query string per RFC 3986
1144-
// Section 3.4:
1145-
// query = *( pchar / "/" / "?" )
1146-
// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
1147-
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1148-
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1149-
// / "*" / "+" / "," / ";" / "="
1150-
func validQuery(s string) bool {
1151-
pctEnc := 0
1152-
1153-
for _, r := range s {
1154-
if pctEnc > 0 {
1155-
if uint32(r) > 255 || !ishex(byte(r)) {
1156-
return false
1157-
}
1158-
pctEnc--
1159-
continue
1160-
} else if r == '%' {
1161-
pctEnc = 2
1162-
continue
1163-
}
1164-
1165-
if 'A' <= r && r <= 'Z' {
1166-
continue
1167-
}
1168-
if 'a' <= r && r <= 'z' {
1169-
continue
1170-
}
1171-
if '0' <= r && r <= '9' {
1172-
continue
1173-
}
1174-
switch r {
1175-
case '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')',
1176-
'*', '+', ',', ';', '=', ':', '@', '/', '?':
1177-
continue
1178-
default:
1179-
return false
1180-
}
1181-
}
1182-
1183-
return true
1184-
}

src/net/url/url_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,6 @@ var urltests = []URLTest{
590590
},
591591
"mailto:?subject=hi",
592592
},
593-
{
594-
"https://example.com/search?q=Фотки собак&source=lnms",
595-
&URL{
596-
Scheme: "https",
597-
Host: "example.com",
598-
Path: "/search",
599-
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",
600-
},
601-
"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",
602-
},
603593
}
604594

605595
// more useful string for debugging than fmt's struct printer
@@ -1449,7 +1439,6 @@ func TestParseErrors(t *testing.T) {
14491439
{"cache_object:foo", true},
14501440
{"cache_object:foo/bar", true},
14511441
{"cache_object/:foo/bar", false},
1452-
{"https://example.com/search?q=Фотки собак&source=lnms", false},
14531442
}
14541443
for _, tt := range tests {
14551444
u, err := Parse(tt.in)

0 commit comments

Comments
 (0)