-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
encoding/json: string option (struct tag) on string field with SetEscapeHTML(false) escapes anyway #34154
Labels
Milestone
Comments
breml
added a commit
to breml/go
that referenced
this issue
Sep 6, 2019
Since Go 1.2 every string can be marshaled to JSON without error even if it contains invalid UTF-8 byte sequences. Therefore there is no need to use Marshal again for the only reason of enclosing the string in double quotes. Not using Marshal here also removes the error check as there has not been a way for Marshal to fail anyway. Additionally, this code runs significantly faster for quoted string fields (30 - 45% in my measurements, depending on the length of the string that is processed). Fixes: golang#34154
Change https://golang.org/cl/193604 mentions this issue: |
breml
added a commit
to breml/go
that referenced
this issue
Sep 9, 2019
Since Go 1.2 every string can be marshaled to JSON without error even if it contains invalid UTF-8 byte sequences. Therefore there is no need to use Marshal again for the only reason of enclosing the string in double quotes. Not using Marshal here also removes the error check as there has not been a way for Marshal to fail anyway. Additionally, this code runs significantly faster for quoted string fields (30 - 45% in my measurements, depending on the length of the string that is processed). Fixes: golang#34154
breml
added a commit
to breml/go
that referenced
this issue
Sep 9, 2019
Since Go 1.2 every string can be marshaled to JSON without error even if it contains invalid UTF-8 byte sequences. Therefore there is no need to use Marshal again for the only reason of enclosing the string in double quotes. Not using Marshal here also removes the error check as there has not been a way for Marshal to fail anyway. Additionally, this code runs significantly faster for quoted string fields (30 - 45% in my measurements, depending on the length of the string that is processed). Fixes: golang#34154
breml
added a commit
to breml/go
that referenced
this issue
Sep 10, 2019
Since Go 1.2 every string can be marshaled to JSON without error even if it contains invalid UTF-8 byte sequences. Therefore there is no need to use Marshal again for the only reason of enclosing the string in double quotes. Not using Marshal here also removes the error check as there has not been a way for Marshal to fail anyway. name old time/op new time/op delta Issue34127-4 360ns ± 3% 200ns ± 3% -44.56% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Issue34127-4 56.0B ± 0% 40.0B ± 0% -28.57% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Issue34127-4 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Fixes golang#34154
FiloSottile
added
the
NeedsFix
The path to resolution is known, but the work has not been done.
label
Sep 10, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
If using
encoding/json.NewEncoder
withSetEscapeHTML(false)
an a field, that has thestring
option in the struct tags set, the HTML content gets escaped anyways.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
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
#34127 does fix this issue
The text was updated successfully, but these errors were encountered: