aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/encoding/json/decode_test.go
diff options
context:
space:
mode:
authorMichael Chaten <mchaten@gmail.com>2012-05-03 17:35:44 -0400
committerRuss Cox <rsc@golang.org>2012-05-03 17:35:44 -0400
commit3fab2a97e4ae677e74a4569e924ddd0d56cf4a78 (patch)
tree76bf16696698a4fbaf3625ab115ef4ed51190097 /src/pkg/encoding/json/decode_test.go
parent61060acdc12ef0e0b9ff2250efdf8da10d53c5a2 (diff)
downloadgo-3fab2a97e4ae677e74a4569e924ddd0d56cf4a78.tar.xz
encoding/json: Fix panic when trying to unmarshal the empty string into an integer
Fixes #3450. R=rsc, bradfitz CC=golang-dev https://golang.org/cl/6035050
Diffstat (limited to 'src/pkg/encoding/json/decode_test.go')
-rw-r--r--src/pkg/encoding/json/decode_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/pkg/encoding/json/decode_test.go b/src/pkg/encoding/json/decode_test.go
index 78768c8ba1..4f6a9b64ef 100644
--- a/src/pkg/encoding/json/decode_test.go
+++ b/src/pkg/encoding/json/decode_test.go
@@ -646,3 +646,22 @@ func TestAnonymous(t *testing.T) {
t.Fatal("Unmarshal: did set T.Y")
}
}
+
+// Test that the empty string doesn't panic decoding when ,string is specified
+// Issue 3450
+func TestEmptyString(t *testing.T) {
+ type T2 struct {
+ Number1 int `json:",string"`
+ Number2 int `json:",string"`
+ }
+ data := `{"Number1":"1", "Number2":""}`
+ dec := NewDecoder(strings.NewReader(data))
+ var t2 T2
+ err := dec.Decode(&t2)
+ if err == nil {
+ t.Fatal("Decode: did not return error")
+ }
+ if t2.Number1 != 1 {
+ t.Fatal("Decode: did not set Number1")
+ }
+}