Skip to content

Commit 548dcfe

Browse files
1911860538gopherbot
1911860538
authored andcommitted
net/url: clarify why @ is allowed in userinfo
Add comment to clarify why '@' is allowed in validUserinfo func. Change-Id: Ia9845bc40fea6c34093434d57bb1be4ddbc70b84 GitHub-Last-Rev: ce65168 GitHub-Pull-Request: #73195 Reviewed-on: https://go-review.googlesource.com/c/go/+/663455 Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent 5ab9d96 commit 548dcfe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/net/url/url.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,18 @@ func validUserinfo(s string) bool {
12801280
}
12811281
switch r {
12821282
case '-', '.', '_', ':', '~', '!', '$', '&', '\'',
1283-
'(', ')', '*', '+', ',', ';', '=', '%', '@':
1283+
'(', ')', '*', '+', ',', ';', '=', '%':
1284+
continue
1285+
case '@':
1286+
// `RFC 3986 section 3.2.1` does not allow '@' in userinfo.
1287+
// It is a delimiter between userinfo and host.
1288+
// However, URLs are diverse, and in some cases,
1289+
// the userinfo may contain an '@' character,
1290+
// for example, in "http://username:p@[email protected]",
1291+
// the string "username:p@ssword" should be treated as valid userinfo.
1292+
// Ref:
1293+
// https://go.dev/issue/3439
1294+
// https://go.dev/issue/22655
12841295
continue
12851296
default:
12861297
return false

0 commit comments

Comments
 (0)