-
-
Notifications
You must be signed in to change notification settings - Fork 188
unexpected behavior when buffer ends with backslash #384
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Version
v0.9.10
Summary
In double quote case (") of Stream.skipObject function, if s.buf ends with backslash (\), the character right next to backslash doesn't escaped.
Way to reproduce this issue
test.json
{"data": "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\""}- 511th character of the json is backslash
- initial buffer size of the stream is 512, so 512th character of a buffer is
\0 - 512th character of the json is double quote, which is doesn't escaped and caused this issue
main.go
package main
import (
"fmt"
"os"
"github.com/goccy/go-json"
)
type test struct{}
func (t test) UnmarshalJSON(bytes []byte) error {
return nil
}
func main() {
file, err := os.Open("./test.json")
if err != nil {
panic(fmt.Errorf("file open failed: %w", err))
}
defer file.Close()
d := json.NewDecoder(file)
var t test
if err := d.Decode(&t); err != nil {
panic(fmt.Errorf("decode failed: %w", err))
}
}output
panic: decode failed: json: string of object unexpected end of JSON input
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working