Test that the empty string doesn't panic decoding when ,string is specified Issue 3450
(t *testing.T)
| 1619 | // Test that the empty string doesn't panic decoding when ,string is specified |
| 1620 | // Issue 3450 |
| 1621 | func TestEmptyString(t *testing.T) { |
| 1622 | type T2 struct { |
| 1623 | Number1 int `json:",string"` |
| 1624 | Number2 int `json:",string"` |
| 1625 | } |
| 1626 | data := `{"Number1":"1", "Number2":""}` |
| 1627 | dec := NewDecoder(strings.NewReader(data)) |
| 1628 | var t2 T2 |
| 1629 | err := dec.Decode(&t2) |
| 1630 | if err == nil { |
| 1631 | t.Fatal("Decode: did not return error") |
| 1632 | } |
| 1633 | if t2.Number1 != 1 { |
| 1634 | t.Fatal("Decode: did not set Number1") |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | // Test that a null for ,string is not replaced with the previous quoted string (issue 7046). |
| 1639 | // It should also not be an error (issue 2540, issue 8587). |
nothing calls this directly
no test coverage detected
searching dependent graphs…