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

Unmarshal modifies input data #138

Open
jpcosal opened this issue Jan 31, 2020 · 1 comment
Open

Unmarshal modifies input data #138

jpcosal opened this issue Jan 31, 2020 · 1 comment

Comments

@jpcosal
Copy link

jpcosal commented Jan 31, 2020

When input data contains strings with escaped characters (e.g. "/"), input byte array passed to gojay.Unmarshal is altered.

A sample code is given below

package main

import (
	"log"

	"github.com/francoispqt/gojay"
)

func main() {
	data := []byte(`"msn.com\/fr-fr"`)
	var s string
	if err := gojay.Unmarshal(data, &s); err != nil {
		log.Println(err)
	}
	log.Printf("buffer is: %s\n", string(data))
}

This outputs "msn.com/fr-fr"", while original buffer is "msn.com\/fr-fr".
This is a problem because we need to use the original buffer as is to do other processing.

@skidder
Copy link

skidder commented Apr 2, 2020

I've encountered this problem, too. Input that contains escape characters is unescaped, and a quote is added to the end of the buffer for each escape character present in the input:

package main

import (
	"log"

	"github.com/francoispqt/gojay"
)

func main() {
	data := []byte(`"\/foo\/bar"`)
	var s string
	if err := gojay.Unmarshal(data, &s); err != nil {
		log.Println(err)
	}
	log.Printf("buffer is: %s\n", string(data))
}

Output:

→ go run main.go 
2020/04/02 08:07:57 buffer is: "/foo/bar"""

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