diff options
Diffstat (limited to 'src/encoding/json/encode.go')
| -rw-r--r-- | src/encoding/json/encode.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 6af2fabeb4..364e2724b7 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -14,6 +14,7 @@ import ( "bytes" "encoding" "encoding/base64" + "fmt" "math" "reflect" "runtime" @@ -529,8 +530,12 @@ var ( func stringEncoder(e *encodeState, v reflect.Value, quoted bool) { if v.Type() == numberType { numStr := v.String() + // In Go1.5 the empty string encodes to "0", while this is not a valid number literal + // we keep compatibility so check validity after this. if numStr == "" { numStr = "0" // Number's zero-val + } else if !Number(numStr).IsValid() { + e.error(fmt.Errorf("json: invalid number literal, trying to marshal %s", v.String())) } e.WriteString(numStr) return |
