]> Cypherpunks repositories - gostls13.git/commit
encoding/json: obey SetEscapeHTML in all MarshalJSON cases
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 2 Jul 2019 21:56:41 +0000 (23:56 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Sat, 6 Jul 2019 13:25:59 +0000 (13:25 +0000)
commit13327f219e5bb0f050eb41f25f9dd07ec3d56f32
treee8e629756c5151e3e97d81f1ba8ec2f22fa8d5f9
parenta2fb5cd823f5223070c3cce741dd5b3879bac21b
encoding/json: obey SetEscapeHTML in all MarshalJSON cases

It wasn't obeyed in the case where the MarshalJSON method uses a pointer
receiver, and the encoder grabs the address of a value to find that
method. addrMarshalerEncoder is the function that does this work, but it
ignored opts.escapeHTML.

Here's the before and after of the added test case, which was failing
before the fix. Now the two cases are correct and consistent.

{"NonPtr":"<str>","Ptr":"\u003cstr\u003e"}
{"NonPtr":"<str>","Ptr":"<str>"}

Fixes #32896.

Change-Id: Idc53077ece074973558bd3bb5ad036380db0d02c
Reviewed-on: https://go-review.googlesource.com/c/go/+/184757
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Caleb Spare <cespare@gmail.com>
src/encoding/json/encode.go
src/encoding/json/stream_test.go