aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/decode.go
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2018-09-11 22:09:00 +0200
committerDaniel Martí <mvdan@mvdan.cc>2018-09-12 06:48:09 +0000
commitdc3680865a880e4f24ad40474b27c8ca276d8e5d (patch)
tree2b102742bbeef7109f65e441c778760476bee39c /src/encoding/json/decode.go
parent023dbb188dda6aa49ccc41c8e38f2703700b3f5a (diff)
downloadgo-dc3680865a880e4f24ad40474b27c8ca276d8e5d.tar.xz
encoding/json: more tests to cover decoding edge cases
The overall coverage of the json package goes up from 90.8% to 91.3%. While at it, apply two minor code simplifications found while inspecting the HTML coverage report. Change-Id: I0fba968afeedc813b1385e4bde72d93b878854d7 Reviewed-on: https://go-review.googlesource.com/134735 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/encoding/json/decode.go')
-rw-r--r--src/encoding/json/decode.go23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go
index 82dc78083a..dbff2d0631 100644
--- a/src/encoding/json/decode.go
+++ b/src/encoding/json/decode.go
@@ -533,8 +533,7 @@ func (d *decodeState) array(v reflect.Value) error {
d.saveError(&UnmarshalTypeError{Value: "array", Type: v.Type(), Offset: int64(d.off)})
d.skip()
return nil
- case reflect.Array:
- case reflect.Slice:
+ case reflect.Array, reflect.Slice:
break
}
@@ -871,18 +870,16 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
if item[0] != '"' {
if fromQuoted {
d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
- } else {
- var val string
- switch item[0] {
- case 'n':
- val = "null"
- case 't', 'f':
- val = "bool"
- default:
- val = "number"
- }
- d.saveError(&UnmarshalTypeError{Value: val, Type: v.Type(), Offset: int64(d.readIndex())})
+ return nil
+ }
+ val := "number"
+ switch item[0] {
+ case 'n':
+ val = "null"
+ case 't', 'f':
+ val = "bool"
}
+ d.saveError(&UnmarshalTypeError{Value: val, Type: v.Type(), Offset: int64(d.readIndex())})
return nil
}
s, ok := unquoteBytes(item)