json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.33k stars 1.02k forks source link

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

Open kz-sher opened 1 year ago

kz-sher commented 1 year ago

See #663

kz-sher commented 1 year ago

@taowen

taowen commented 1 year ago

split it into two functions, duplicate the code is ok

kz-sher commented 1 year ago

done

taowen commented 1 year ago

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

kz-sher commented 1 year ago

@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.

taowen commented 1 year ago

they can opt to use the standard library

kz-sher commented 1 year ago

@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.

taowen commented 1 year ago

you may add my wechat "nctaowen"