Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryAsStringExtension panic with escape character #668

Open
Arrow-Li opened this issue Mar 14, 2023 · 1 comment
Open

BinaryAsStringExtension panic with escape character #668

Arrow-Li opened this issue Mar 14, 2023 · 1 comment

Comments

@Arrow-Li
Copy link

  • 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
Copy link

kz-sher commented Mar 16, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants