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

Marshaling does not agree with json.Encoder #86

Open
barkyq opened this issue Jan 15, 2023 · 0 comments
Open

Marshaling does not agree with json.Encoder #86

barkyq opened this issue Jan 15, 2023 · 0 comments

Comments

@barkyq
Copy link

barkyq commented Jan 15, 2023

The marshaling uses some form of string escaping (via strconv.Quote), which does not preserve the underlying UTF-8 representation.
This causes signature verification to fail in nbd-wtf/go-nostr#28 (an incompatibility with clients written in other languages).

Is it possible to add an option to disable string escaping? This option is present in the standard encoding/json package, see https://pkg.go.dev/encoding/json#Marshal, SetEscapeHTML.

Minimal working example:

import (
	"encoding/json"
	"fmt"
	"github.com/valyala/fastjson"
)
func main() {
	a := fastjson.Arena{}
	s := string(rune(142)) + "\n"
	val := a.NewString(s)
	buf1 := val.MarshalTo(nil)
	buf2, _ := json.Marshal(s)
	fmt.Printf("%x\n", buf1)
	fmt.Printf("%x\n", buf2)
}

returns:

225c75303038655c6e22
22c28e5c6e22
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

1 participant