Skip to content

Commit 8165599

Browse files
author
1911860538
committed
net/url: clarify why @ is allowed in userinfo
1 parent 4fd76d2 commit 8165599

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/net/url/url.go

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

0 commit comments

Comments
 (0)