diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-25 20:56:26 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-25 20:56:26 +0000 |
commit | 422eaae5fe0038ad189b8fd28cfd6a7094d67ae1 (patch) | |
tree | c68d6b2a9f5b82a23171b0a488a4b7e5c63ad860 /libgo/go/encoding/json/decode.go | |
parent | e0f3ea3ed4b9d0bce9f4c14762e4257ba62c8fba (diff) | |
download | ppe42-gcc-422eaae5fe0038ad189b8fd28cfd6a7094d67ae1.tar.gz ppe42-gcc-422eaae5fe0038ad189b8fd28cfd6a7094d67ae1.zip |
libgo: Update to weekly.2012-01-15.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183539 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/encoding/json/decode.go')
-rw-r--r-- | libgo/go/encoding/json/decode.go | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/libgo/go/encoding/json/decode.go b/libgo/go/encoding/json/decode.go index 8287b330034..87076b53dc0 100644 --- a/libgo/go/encoding/json/decode.go +++ b/libgo/go/encoding/json/decode.go @@ -10,6 +10,7 @@ package json import ( "encoding/base64" "errors" + "fmt" "reflect" "runtime" "strconv" @@ -538,7 +539,7 @@ func (d *decodeState) object(v reflect.Value) { // Read value. if destring { d.value(reflect.ValueOf(&d.tempstr)) - d.literalStore([]byte(d.tempstr), subv) + d.literalStore([]byte(d.tempstr), subv, true) } else { d.value(subv) } @@ -571,11 +572,15 @@ func (d *decodeState) literal(v reflect.Value) { d.off-- d.scan.undo(op) - d.literalStore(d.data[start:d.off], v) + d.literalStore(d.data[start:d.off], v, false) } // literalStore decodes a literal stored in item into v. -func (d *decodeState) literalStore(item []byte, v reflect.Value) { +// +// fromQuoted indicates whether this literal came from unwrapping a +// string from the ",string" struct tag option. this is used only to +// produce more helpful error messages. +func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool) { // Check for unmarshaler. wantptr := item[0] == 'n' // null unmarshaler, pv := d.indirect(v, wantptr) @@ -601,7 +606,11 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) { value := c == 't' switch v.Kind() { default: - d.saveError(&UnmarshalTypeError{"bool", v.Type()}) + if fromQuoted { + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.saveError(&UnmarshalTypeError{"bool", v.Type()}) + } case reflect.Bool: v.SetBool(value) case reflect.Interface: @@ -611,7 +620,11 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) { case '"': // string s, ok := unquoteBytes(item) if !ok { - d.error(errPhase) + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } } switch v.Kind() { default: @@ -636,12 +649,20 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) { default: // number if c != '-' && (c < '0' || c > '9') { - d.error(errPhase) + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } } s := string(item) switch v.Kind() { default: - d.error(&UnmarshalTypeError{"number", v.Type()}) + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(&UnmarshalTypeError{"number", v.Type()}) + } case reflect.Interface: n, err := strconv.ParseFloat(s, 64) if err != nil { |