]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4493] Proposed fix
authorFrancis Dupont <fdupont@isc.org>
Tue, 5 May 2026 08:13:42 +0000 (10:13 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 5 May 2026 21:11:36 +0000 (23:11 +0200)
src/lib/cc/data.cc
src/lib/cc/tests/data_unittests.cc

index 4229d60509a9af5dfcccbf40b42b4798b1095c8c..a2bee51065aac45e6f9e4e9f159fec5a233664ae 100644 (file)
@@ -917,12 +917,12 @@ DoubleElement::toJSON(std::ostream& ss, unsigned) const {
     // zeros, however this produces strings without decimal points
     // for whole number values.  When reparsed this will create
     // IntElements not DoubleElements.  Rather than used a fixed
-    // precision, we'll just tack on an ".0" when the decimal point
-    // is missing.
+    // precision, we'll just tack on an ".0" when there is no
+    // fractional nor exponent parts.
     ostringstream val_ss;
     val_ss << doubleValue();
     ss << val_ss.str();
-    if (val_ss.str().find_first_of('.') == string::npos) {
+    if (val_ss.str().find_first_of(".eE") == string::npos) {
         ss << ".0";
     }
 }
index 577f374157e3eb087c197d317d1f21261bfa6a6e..10bc3607f5fb5706afebacb0e70589f96bf79679 100644 (file)
@@ -102,6 +102,7 @@ TEST(Element, toAndFromJson) {
     sv.push_back("-1");
     sv.push_back("-1.234");
     sv.push_back("-123.456");
+    sv.push_back("1e+30");
     // We should confirm that our string handling is 8-bit clean.
     // At one point we were using char-length data and comparing to EOF,
     // which means that character '\xFF' would not parse properly.
@@ -188,6 +189,10 @@ TEST(Element, toAndFromJson) {
     EXPECT_EQ("0.01", Element::fromJSON("1.0e-2")->str());
     EXPECT_EQ("0.012", Element::fromJSON("1.2e-2")->str());
     EXPECT_EQ("0.012", Element::fromJSON("1.2E-2")->str());
+    EXPECT_EQ("1e+30", Element::fromJSON("1e30")->str());
+    EXPECT_EQ("1e+30", Element::fromJSON("1E30")->str());
+    EXPECT_EQ("1e+30", Element::fromJSON("1E+30")->str());
+    EXPECT_EQ("1e-30", Element::fromJSON("1E-30")->str());
     EXPECT_EQ("\"\"", Element::fromJSON("  \n \t \r \f \b \"\" \n \f \t \r \b")->str());
     EXPECT_EQ("{  }", Element::fromJSON("{  \n  \r \t  \b \f }")->str());
     EXPECT_EQ("[  ]", Element::fromJSON("[  \n  \r \f \t  \b  ]")->str());