aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author1911860538 <alxps1911@gmail.com>2025-04-11 15:14:11 +0000
committerGopher Robot <gobot@golang.org>2025-04-16 15:01:23 -0700
commit548dcfea1aa3dfbc975a417dc609c4f372a03042 (patch)
treeb59902b4b1f1fdc56d8cbd5c4a161391f51b9fb9
parent5ab9d9660412be2887ae5adba6198f029bcbb4a9 (diff)
downloadgo-548dcfea1aa3dfbc975a417dc609c4f372a03042.tar.xz
net/url: clarify why @ is allowed in userinfo
Add comment to clarify why '@' is allowed in validUserinfo func. Change-Id: Ia9845bc40fea6c34093434d57bb1be4ddbc70b84 GitHub-Last-Rev: ce65168ab03afd879ad028de295f6adb7ee1c97d GitHub-Pull-Request: golang/go#73195 Reviewed-on: https://go-review.googlesource.com/c/go/+/663455 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
-rw-r--r--src/net/url/url.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/net/url/url.go b/src/net/url/url.go
index 8786d9655b..2a57659460 100644
--- a/src/net/url/url.go
+++ b/src/net/url/url.go
@@ -1280,7 +1280,18 @@ func validUserinfo(s string) bool {
}
switch r {
case '-', '.', '_', ':', '~', '!', '$', '&', '\'',
- '(', ')', '*', '+', ',', ';', '=', '%', '@':
+ '(', ')', '*', '+', ',', ';', '=', '%':
+ continue
+ case '@':
+ // `RFC 3986 section 3.2.1` does not allow '@' in userinfo.
+ // It is a delimiter between userinfo and host.
+ // However, URLs are diverse, and in some cases,
+ // the userinfo may contain an '@' character,
+ // for example, in "http://username:p@ssword@google.com",
+ // the string "username:p@ssword" should be treated as valid userinfo.
+ // Ref:
+ // https://go.dev/issue/3439
+ // https://go.dev/issue/22655
continue
default:
return false