From 6e154ee727e3282704c847303c8abde16c69a7de Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 30 Jan 2021 02:03:31 +0900 Subject: [PATCH] Fix decoding of escape char at UnmarshalJSON --- decode_interface.go | 1 + decode_test.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/decode_interface.go b/decode_interface.go index 2138f68..840718e 100644 --- a/decode_interface.go +++ b/decode_interface.go @@ -218,6 +218,7 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (i switch buf[cursor] { case '\\': cursor++ + continue case '"': literal := buf[start:cursor] cursor++ diff --git a/decode_test.go b/decode_test.go index afea9ef..8836b36 100644 --- a/decode_test.go +++ b/decode_test.go @@ -226,6 +226,14 @@ func Test_Decoder(t *testing.T) { }) } +func TestIssue98(t *testing.T) { + data := "[\"\\" + var v interface{} + if err := json.Unmarshal([]byte(data), &v); err == nil { + t.Fatal("expected error") + } +} + func Test_Decoder_UseNumber(t *testing.T) { dec := json.NewDecoder(strings.NewReader(`{"a": 3.14}`)) dec.UseNumber()