Fix removeEmptyPort
remove hasPort and simplify logic
#76651
diff --git a/src/net/http/http.go b/src/net/http/http.go
index d346e60..c7a7901 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -113,8 +113,8 @@
// 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
}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I spotted some possible problems with your PR:
1. The commit title should start with the primary affected package name followed by a colon, like "net/http: improve [...]".
2. The first word in the commit title after the package should be a lowercase English word (usually a verb).
Please address any problems by updating the GitHub PR.
When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.
To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.
For more details, see:
(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if len(host) > 0 && host[len(host)-1] == ':' {Thanks. This will be clearer and simpler using strings.CutSuffix.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I spotted some possible problems with your PR:
1. The commit title should start with the primary affected package name followed by a colon, like "net/http: improve [...]".
2. The first word in the commit title after the package should be a lowercase English word (usually a verb).Please address any problems by updating the GitHub PR.
When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.
To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.
For more details, see:
- [how to update commit messages](https://go.dev/wiki/GerritBot/#how-does-gerritbot-determine-the-final-commit-message) for PRs imported into Gerrit.
- the Go project's [conventions for commit messages](https://go.dev/doc/contribute#commit_messages) that you should follow.
(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)
Done
Thanks. This will be clearer and simpler using strings.CutSuffix.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
#76651```
net/http: simplify removeEmptyPort
Fixes #76651
```
All CLs should have a summary line beginning with the affected package(s).
The "Fixes #XXX" syntax is understood by gopherbot and used to associate CLs with issues.
host, _ = strings.CutSuffix(host, ":")Why not `return strings.TrimSuffix(host, ":")`?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
By the way, I just noticed that this CL and https://go.dev/cl/725740 are both cleaning up the same code.
CL 725740 does a bit more and was created first (although only by 20 minutes), so perhaps we should go with that one.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
```
net/http: simplify removeEmptyPortFixes #76651
```All CLs should have a summary line beginning with the affected package(s).
The "Fixes #XXX" syntax is understood by gopherbot and used to associate CLs with issues.
Done
Why not `return strings.TrimSuffix(host, ":")`?
You are right
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |