BinaryAsStringExtension panic with escape character
Arrow-Li opened this issue · 1 comments
Arrow-Li commented
-
Version:github.com/json-iterator/go v1.1.12
-
A json like below be panic when unmarshal with BinaryAsStringExtension
{
"F": "{\"abc\":\"123\"}"
}- Test Code
package main
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
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)