From c4be790c0e20bfa4def3103392f404de201b3487 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Wed, 15 Jul 2015 16:12:05 +0200 Subject: encoding/json: check if Number is valid json.Number is a special case which didn't have any checks and could result in invalid JSON. Fixes #10281 Change-Id: Ie3e726e4d6bf6a6aba535d36f6107013ceac913a Reviewed-on: https://go-review.googlesource.com/12250 Reviewed-by: Russ Cox --- src/encoding/json/encode_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/encoding/json/encode_test.go') diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go index 2206b2ee2e..c00491e00c 100644 --- a/src/encoding/json/encode_test.go +++ b/src/encoding/json/encode_test.go @@ -437,6 +437,18 @@ func TestIssue6458(t *testing.T) { } } +func TestIssue10281(t *testing.T) { + type Foo struct { + N Number + } + x := Foo{Number(`invalid`)} + + b, err := Marshal(&x) + if err == nil { + t.Errorf("Marshal(&x) = %#q; want error", b) + } +} + func TestHTMLEscape(t *testing.T) { var b, want bytes.Buffer m := `{"M":"foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `"}` -- cgit v1.3