diff options
author | Russ Cox <rsc@golang.org> | 2015-07-30 14:05:04 +0000 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2015-07-30 20:00:56 +0000 |
commit | 80e6d638bf309181eadcb3fecbe99d2d8518e364 (patch) | |
tree | af5a03077ee8e483c5ebc9a13c7a4310b6bddc71 /src/encoding/json/decode_test.go | |
parent | e0c180c44f306997faf7ac4d5d29353fd9518997 (diff) | |
download | go-git-80e6d638bf309181eadcb3fecbe99d2d8518e364.tar.gz |
encoding/json: revert "fix decoding of JSON null values"
Fixes #11912.
Fixes #11937.
This reverts commit 1a99ba55df902a2657d1ccfc52a60024c22dba98.
Change-Id: I32b76053fdabc59f28ca5bedf1b15c0baa8afae1
Reviewed-on: https://go-review.googlesource.com/12893
Reviewed-by: Didier Spezia <didier.06@gmail.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/encoding/json/decode_test.go')
-rw-r--r-- | src/encoding/json/decode_test.go | 76 |
1 files changed, 1 insertions, 75 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index 8c449d4784..8aa158f08c 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -1322,48 +1322,7 @@ func (t *Time3339) UnmarshalJSON(b []byte) error { return nil } -// A Time-like type supporting the json Unmarshal interface -type AJson struct { - T int -} - -func (t *AJson) UnmarshalJSON(b []byte) error { - if len(b) < 2 || b[0] != '"' || b[len(b)-1] != '"' { - return fmt.Errorf("types: failed to unmarshal non-string value %q", b) - } - if _, err := fmt.Sscanf(string(b[1:len(b)-1]), "%d", &t.T); err != nil { - return err - } - return nil -} - -// A Time-like type supporting the text Unmarshal interface -type AText struct { - T int -} - -func (t *AText) UnmarshalText(b []byte) error { - if len(b) < 2 || b[0] != '"' || b[len(b)-1] != '"' { - return fmt.Errorf("types: failed to unmarshal non-string value %q", b) - } - if _, err := fmt.Sscanf(string(b[1:len(b)-1]), "%d", &t.T); err != nil { - return err - } - return nil -} - -// This type mixes pointers and structures, supporting json or text Unmarshal interfaces -type STime struct { - X int - J1 AJson - J2 *AJson - J3 **AJson - T1 AText - T2 *AText - T3 **AText -} - -func TestUnmarshalJSONLiteralError1(t *testing.T) { +func TestUnmarshalJSONLiteralError(t *testing.T) { var t3 Time3339 err := Unmarshal([]byte(`"0000-00-00T00:00:00Z"`), &t3) if err == nil { @@ -1372,39 +1331,6 @@ func TestUnmarshalJSONLiteralError1(t *testing.T) { if !strings.Contains(err.Error(), "range") { t.Errorf("got err = %v; want out of range error", err) } - - out := time.Now() - want := out - err = Unmarshal([]byte(`null`), &out) - if err != nil { - t.Fatalf("got err = %v; no error was expected", err) - } - if out != want { - t.Fatalf("got %q, want %q", out, want) - } -} - -func TestUnmarshalJSONLiteralError2(t *testing.T) { - out := STime{ - X: 1, - J1: AJson{2}, - J2: &AJson{3}, - J3: new(*AJson), - T1: AText{5}, - T2: &AText{6}, - T3: new(*AText), - } - want := out - want.J2 = nil - want.T2 = nil - // Keep the spaces as they are in the following line - err := Unmarshal([]byte(`{"X":1,"J1":null,"J2":null,"J3": null,"T1":null ,"T2": null , "T3":null}`), &out) - if err != nil { - t.Fatalf("got err = %v; no error was expected", err) - } - if out != want { - t.Fatalf("got %v, want %v", out, want) - } } // Test that extra object elements in an array do not result in a |