go icon indicating copy to clipboard operation
go copied to clipboard

Fix wrong behavior in marshalling invalid UTF-8 byte with EscapeHTML=false

Open kz-sher opened this issue 2 years ago • 8 comments

See #663

kz-sher avatar Mar 09 '23 04:03 kz-sher

@taowen

kz-sher avatar Mar 13 '23 09:03 kz-sher

split it into two functions, duplicate the code is ok

taowen avatar Mar 13 '23 09:03 taowen

done

kz-sher avatar Mar 13 '23 09:03 kz-sher

this will affect all users of writeStringSlowPath. do not want to make such a impactful change.

taowen avatar Mar 13 '23 11:03 taowen

@taowen This is the same with https://go.dev/src/encoding/json/encode.go#L1029. The code changes essentially restrict contents to be UTF-8. According to https://github.com/golang/go/issues/36686#issuecomment-576963338, I think the users should have accepted this behavior. If they opt for another encodings, they should follow JSON convention by doing transformation in advance.

kz-sher avatar Mar 13 '23 11:03 kz-sher

they can opt to use the standard library

taowen avatar Mar 15 '23 11:03 taowen

@taowen I think jsoniter is created to be one of the better alternatives of official JSON pkg. Should you be considering this feature to be added in another ways such as having Config.MarshalByteWithUTF8Coerced option? It seems like its Java version has this support.

kz-sher avatar Mar 16 '23 02:03 kz-sher

you may add my wechat "nctaowen"

taowen avatar Mar 16 '23 15:03 taowen