-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: Error adds newline to message #50186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The new line is added by Fprintln https://cs.opensource.google/go/go/+/refs/tags/go1.17.5:src/net/http/server.go;drc=3c50f2739136bb4a6ff529c6ec975723a047a741;l=2060 |
Yep, but I'm unsure that's a correct way. If it is, then I'll have to fix that @ client side apps. |
What is the problem that the new line causes? |
Line break increases height of any UI element which is used to show that message (user side). Even if it's you who form these messages, you have to forcibly use Trim() (or any of it's equivalent from any lang) @ client side. Then you do the same for logging. If you concat these strings, you go even further. My vision is that if the string is empty, it should be empty, but not a line break/whitespace(s) etc. |
Duplicate of #24530 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Microsoft Windows [Version 6.3.9600]
What did you do?
I use a small program to test GET requests to API:
What did you expect to see?
http.Error(w, "", http.StatusForbidden) - expected an empty message here
http.Error(w, "Wrong API key!", http.StatusForbidden) - expected "Wrong API key!" message
What did you see instead?
http.Error(w, "", http.StatusForbidden) - "\n" message here
http.Error(w, "Wrong API key!", http.StatusForbidden) - "Wrong API key!\n" message here
From Chrome:

From Visual Studio:

The text was updated successfully, but these errors were encountered: