Skip to content

zero byte in error string #354

Closed
Closed
@jfcg

Description

Hi,
For Go 1.17.8 and go-json 0.9.6 this code:

package main

import (
	"fmt"
	"github.com/goccy/go-json"
)

func main() {
	buf := []byte{}
	obj := struct{ X int }{}

	if err := json.Unmarshal(buf, &obj); err != nil {
		s := err.Error()
		fmt.Println(s)
		fmt.Println(s[19])
	}
}

prints:

invalid character '' looking for beginning of value
0

so there is a zero byte between single quotes in the error message. This does not sound right as there is no data in buf.
encoding/json does not have this issue and the error message is unexpected end of JSON input.

CC: @ReneWerner87 @efectn

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions