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

Bug: can't decode escaped unicode string #386

Closed
trim21 opened this issue Jul 28, 2022 · 2 comments · Fixed by #387
Closed

Bug: can't decode escaped unicode string #386

trim21 opened this issue Jul 28, 2022 · 2 comments · Fixed by #387

Comments

@trim21
Copy link
Contributor

trim21 commented Jul 28, 2022

unexpected error: json: string unexpected end of JSON input

some other context:

  • it works fine if a is an interface{}
  • it also works fine if using json.Unmarshal, not NewDecoder()
  • this is the minimal case to re-produce this issue, remove any key-value pair from raw json will make go-json works fine.
func TestIssue386(t *testing.T) {
	raw := `{"date": null, "platform": "\u6f2b\u753b", "images": {"small": "https://lain.bgm.tv/pic/cover/s/d2/a1/80048_jp.jpg", "grid": "https://lain.bgm.tv/pic/cover/g/d2/a1/80048_jp.jpg", "large": "https://lain.bgm.tv/pic/cover/l/d2/a1/80048_jp.jpg", "medium": "https://lain.bgm.tv/pic/cover/m/d2/a1/80048_jp.jpg", "common": "https://lain.bgm.tv/pic/cover/c/d2/a1/80048_jp.jpg"}, "summary": "\u5929\u624d\u8a2d\u8a08\u58eb\u30fb\u5929\u5bae\uff08\u3042\u307e\u307f\u3084\uff09\u3092\u62b1\u3048\u308b\u6751\u96e8\u7dcf\u5408\u4f01\u753b\u306f\u3001\u771f\u6c34\u5efa\u8a2d\u3068\u63d0\u643a\u3057\u3066\u300c\u3055\u304d\u305f\u307e\u30a2\u30ea\u30fc\u30ca\u300d\u306e\u30b3\u30f3\u30da\u306b\u512a\u52dd\u3059\u308b\u3053\u3068\u306b\u8ced\u3051\u3066\u3044\u305f\u3002\u3057\u304b\u3057\u3001\u73fe\u77e5\u4e8b\u306e\u6d25\u5730\u7530\uff08\u3064\u3061\u3060\uff09\u306f\u5927\u65e5\u5efa\u8a2d\u306b\u512a\u52dd\u3055\u305b\u3088\u3046\u3068\u6697\u8e8d\u3059\u308b\u3002\u305d\u308c\u306f\u73fe\u77e5\u4e8b\u306e\u6d25\u5730\u7530\u3068\u526f\u77e5\u4e8b\u306e\u592a\u7530\uff08\u304a\u304a\u305f\uff09\u306e\u653f\u6cbb\u751f\u547d\u3092\u5de6\u53f3\u3059\u308b\u4e89\u3044\u3068\u306a\u308a\u2026\u2026!?\u3000\u305d\u3057\u3066\u516c\u5171\u4e8b\u696d\u306b\u6e26\u5dfb\u304f\u6df1\u3044\u95c7\u306b\u842c\u7530\u9280\u6b21\u90ce\uff08\u307e\u3093\u3060\u30fb\u304e\u3093\u3058\u308d\u3046\uff09\u306f\u2026\u2026!?", "name": "\u30df\u30ca\u30df\u306e\u5e1d\u738b (48)"}`

	var a struct {
		Date     *string `json:"date"`
		Platform *string `json:"platform"`
		Summary  string  `json:"summary"`
		Name     string  `json:"name"`
	}

	err := stdjson.NewDecoder(bytes.NewBufferString(raw)).Decode(&a)
	if err != nil {
		t.Errorf("stdjson should not fail: %s", err.Error())
		t.FailNow()
	}

	err = json.NewDecoder(bytes.NewBufferString(raw)).Decode(&a)
	if err != nil {
		t.Errorf("unexpected fail to process unicode escape: %s", err.Error())
		se, ok := err.(*json.SyntaxError)
		if ok {
			t.Errorf("offset %d", se.Offset)
			t.Errorf(raw[se.Offset:])
		}
	}
}
orisano added a commit to orisano/go-json that referenced this issue Jul 29, 2022
@goccy goccy closed this as completed in #387 Aug 1, 2022
goccy added a commit that referenced this issue Aug 1, 2022
Fix stream decoding of escaped character
@trim21
Copy link
Contributor Author

trim21 commented Aug 17, 2022

Can we get a new release including this bug fix? 👀

@goccy
Copy link
Owner

goccy commented Aug 18, 2022

Thank you for the notification, just now I released this fixes as v0.9.11 .

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

Successfully merging a pull request may close this issue.

2 participants