go
go copied to clipboard
BinaryAsStringExtension panic with escape character
-
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)
}
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)