diff --git a/codec/codec_test.go b/codec/codec_test.go index 188e9234..c8f5bbcb 100644 --- a/codec/codec_test.go +++ b/codec/codec_test.go @@ -4193,9 +4193,9 @@ func doTestJsonLargeInteger(t *testing.T, h Handle) { var d *Decoder = NewDecoderBytes(nil, jh) for _, v := range []tt{ {"0", true, true, 0, 0}, - {"0000", true, true, 0, 0}, + {"0000", false, false, 0, 0}, {"0.00e+2", true, true, 0, 0}, - {"000e-2", true, true, 0, 0}, + {"000e-2", false, false, 0, 0}, {"0.00e-2", true, true, 0, 0}, {"9223372036854775807", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 @@ -4384,7 +4384,6 @@ func doTestJsonNumberParsing(t *testing.T, h Handle) { } // try decoding it a uint64 or int64 fint, ffrac = math.Modf(f) - // xdebug2f(">> fint: %v (ffrac: %v) as uint64: %v as float64: %v", fint, ffrac, uint64(fint), float64(uint64(fint))) bv = strconv.AppendFloat(bv[:0], fint, 'E', prec, 64) if f < 0 || fint != float64(uint64(fint)) { goto F64i diff --git a/codec/decimal.go b/codec/decimal.go index dbb33804..effa9646 100644 --- a/codec/decimal.go +++ b/codec/decimal.go @@ -234,6 +234,10 @@ func parseFloat64_custom(b []byte) (f float64, err error) { } func parseUint64_simple(b []byte) (n uint64, ok bool) { + if len(b) > 1 && b[0] == '0' { // punt on numbers with leading zeros + return + } + var i int var n1 uint64 var c uint8 @@ -384,13 +388,23 @@ func readFloat(s []byte, y floatinfo) (r readFloatResult) { i++ } - // we considered punting early if string has length > maxMantDigits, but this doesn't account + // considered punting early if string has length > maxMantDigits, but doesn't account // for trailing 0's e.g. 700000000000000000000 can be encoded exactly as it is 7e20 var nd, ndMant, dp int8 var sawdot, sawexp bool var xu uint64 + if i+1 < slen && s[i] == '0' { + switch s[i+1] { + case '.', 'e', 'E': + // ok + default: + r.bad = true + return + } + } + LOOP: for ; i < slen; i++ { switch s[i] {