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

BinaryAsStringExtension panic with escape character #668

Open Arrow-Li opened 1 year ago

Arrow-Li commented 1 year ago

import ( j "github.com/json-iterator/go" je "github.com/json-iterator/go/extra" )

type D struct { F []byte json:"F" }

func main() { a := "{\"F\":\"{\\"abc\\":\\"123\\"}\"}"

j.RegisterExtension(&je.BinaryAsStringExtension{})

b := new(D)

j.Unmarshal([]byte(a), b)

}

kz-sher commented 1 year ago

According to the source code, all unsafe UTF-8 character will be hexed.

You can try with:

a := "{\"F\":\"{\\\\x22abc\\\\x22:\\\\x22123\\\\x22}\"}"

However, I think this extension could be just an example (my POV: it is not very production-ready)