aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/decode_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-10-07 11:07:04 -0400
committerRuss Cox <rsc@golang.org>2014-10-07 11:07:04 -0400
commit7b2b8edee60788358938dc7d7e04aabeae357b85 (patch)
treee775296d097856a1717a3fe887ed034667c4e735 /src/encoding/json/decode_test.go
parent18172c42ff48611df564e5af8bf00515bbac612a (diff)
downloadgo-7b2b8edee60788358938dc7d7e04aabeae357b85.tar.xz
encoding/json: fix handling of null with ,string fields
Fixes #8587. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews, iant, r https://golang.org/cl/152270044
Diffstat (limited to 'src/encoding/json/decode_test.go')
-rw-r--r--src/encoding/json/decode_test.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go
index d95657d729..7235969b9f 100644
--- a/src/encoding/json/decode_test.go
+++ b/src/encoding/json/decode_test.go
@@ -1070,18 +1070,25 @@ func TestEmptyString(t *testing.T) {
}
}
-// Test that the returned error is non-nil when trying to unmarshal null string into int, for successive ,string option
-// Issue 7046
+// Test that a null for ,string is not replaced with the previous quoted string (issue 7046).
+// It should also not be an error (issue 2540, issue 8587).
func TestNullString(t *testing.T) {
type T struct {
- A int `json:",string"`
- B int `json:",string"`
+ A int `json:",string"`
+ B int `json:",string"`
+ C *int `json:",string"`
}
- data := []byte(`{"A": "1", "B": null}`)
+ data := []byte(`{"A": "1", "B": null, "C": null}`)
var s T
+ s.B = 1
+ s.C = new(int)
+ *s.C = 2
err := Unmarshal(data, &s)
- if err == nil {
- t.Fatalf("expected error; got %v", s)
+ if err != nil {
+ t.Fatalf("Unmarshal: %v")
+ }
+ if s.B != 1 || s.C != nil {
+ t.Fatalf("after Unmarshal, s.B=%d, s.C=%p, want 1, nil", s.B, s.C)
}
}