From 751d42d01ca3205afc3a30a15adcbbe72517d07d Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 9 Jul 2023 14:13:08 +0800 Subject: [PATCH] . --- ujson/src/ujson/Value.scala | 4 ++- ujson/test/src/ujson/SmallJsonTests.scala | 44 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ujson/src/ujson/Value.scala b/ujson/src/ujson/Value.scala index bf7507687..15dbcb22f 100644 --- a/ujson/src/ujson/Value.scala +++ b/ujson/src/ujson/Value.scala @@ -180,7 +180,9 @@ object Value extends AstTransformer[Value]{ override def visitFloat64StringParts(s: CharSequence, decIndex: Int, expIndex: Int, index: Int) = { ujson.Num( - if (decIndex != -1 || expIndex != -1) s.toString.toDouble + if (decIndex != -1 || expIndex != -1 || s.length() >= 19 /*digit count of largest positive long*/) { + s.toString.toDouble + } else ParseUtils.parseIntegralNum(s, decIndex, expIndex, index).toDouble ) } diff --git a/ujson/test/src/ujson/SmallJsonTests.scala b/ujson/test/src/ujson/SmallJsonTests.scala index 11fd25eaa..f06ac1fa9 100644 --- a/ujson/test/src/ujson/SmallJsonTests.scala +++ b/ujson/test/src/ujson/SmallJsonTests.scala @@ -23,6 +23,50 @@ object SmallJsonTests extends TestSuite { } } + test("largeDouble"){ + test("longMaxValue") { + assert( + ujson.read("9223372036854775807").num == + "9223372036854775807".toDouble + ) + } + test("longMinValue") { + assert( + ujson.read("-9223372036854775808").num == + "-9223372036854775808".toDouble + ) + } + test("longMaxValuePlusOne") { + assert( + ujson.read("9223372036854775808").num == + "9223372036854775808".toDouble + ) + } + test("longMinValueMinusOne") { + assert( + ujson.read("-9223372036854775809").num == + "-9223372036854775809".toDouble + ) + } + test("issue240"){ + assert( + ujson.read("28291041994989161181883157038606177750").num == + "28291041994989161181883157038606177750".toDouble + ) + } + test("largeDecimalPoint"){ + assert( + ujson.read("28291041994989161181883157038606177750.28291041994989161181883157038606177750").num == + "28291041994989161181883157038606177750.28291041994989161181883157038606177750".toDouble + ) + } + test("largeDecimalPointExponent"){ + assert( + ujson.read("28291041994989161181883157038606177750.28291041994989161181883157038606177750E123456789").num == + "28291041994989161181883157038606177750.28291041994989161181883157038606177750E123456789".toDouble + ) + } + } test("inputsEu"){ TestUtil.checkParse( """{