From 770502aad811cf5524a00bf60d4dd35a2d22e063 Mon Sep 17 00:00:00 2001 From: baycore Date: Tue, 2 Dec 2025 12:15:30 +0800 Subject: [PATCH 1/3] Fix removeEmptyPort remove hasPort and simplify logic --- src/net/http/http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net/http/http.go b/src/net/http/http.go index d346e60646a08e..c7a790187f18a4 100644 --- a/src/net/http/http.go +++ b/src/net/http/http.go @@ -113,8 +113,8 @@ func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastInd // removeEmptyPort strips the empty port in ":port" to "" // as mandated by RFC 3986 Section 6.2.3. func removeEmptyPort(host string) string { - if hasPort(host) { - return strings.TrimSuffix(host, ":") + if len(host) > 0 && host[len(host)-1] == ':' { + return host[:len(host)-1] } return host } From 2eb154b9d1bca71b811e2842a5696727a103f0b2 Mon Sep 17 00:00:00 2001 From: baycore Date: Tue, 2 Dec 2025 14:22:09 +0800 Subject: [PATCH 2/3] Simplify removeEmptyPort function implementation --- src/net/http/http.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/net/http/http.go b/src/net/http/http.go index c7a790187f18a4..5878596c2dd563 100644 --- a/src/net/http/http.go +++ b/src/net/http/http.go @@ -113,9 +113,7 @@ func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastInd // removeEmptyPort strips the empty port in ":port" to "" // as mandated by RFC 3986 Section 6.2.3. func removeEmptyPort(host string) string { - if len(host) > 0 && host[len(host)-1] == ':' { - return host[:len(host)-1] - } + host, _ = strings.CutSuffix(host, ":") return host } From 647cf556a2ed74d5af6750f79a018d63af4ba507 Mon Sep 17 00:00:00 2001 From: baycore Date: Wed, 3 Dec 2025 10:13:21 +0800 Subject: [PATCH 3/3] Simplify removeEmptyPort function implementation --- src/net/http/http.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/net/http/http.go b/src/net/http/http.go index 5878596c2dd563..2eb905f5491ef6 100644 --- a/src/net/http/http.go +++ b/src/net/http/http.go @@ -113,8 +113,7 @@ func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastInd // removeEmptyPort strips the empty port in ":port" to "" // as mandated by RFC 3986 Section 6.2.3. func removeEmptyPort(host string) string { - host, _ = strings.CutSuffix(host, ":") - return host + return strings.TrimSuffix(host, ":") } // isToken reports whether v is a valid token (https://www.rfc-editor.org/rfc/rfc2616#section-2.2).