diff --git a/src/libxrpl/protocol/STParsedJSON.cpp b/src/libxrpl/protocol/STParsedJSON.cpp index db199a73ed..02dfde3966 100644 --- a/src/libxrpl/protocol/STParsedJSON.cpp +++ b/src/libxrpl/protocol/STParsedJSON.cpp @@ -353,7 +353,9 @@ parseUint32( else { ret = detail::make_stvar( - field, beast::lexicalCastThrow(value.asString())); + field, + safe_cast( + beast::lexicalCastThrow(value.asString()))); } } if (!ret) diff --git a/src/test/protocol/STParsedJSON_test.cpp b/src/test/protocol/STParsedJSON_test.cpp index 082a4624f2..bd62196a99 100644 --- a/src/test/protocol/STParsedJSON_test.cpp +++ b/src/test/protocol/STParsedJSON_test.cpp @@ -140,6 +140,30 @@ public: } } + { + std::string const goodJson( + R"({"CloseResolution":"19","Method":"250",)" + R"("TransactionResult":"tecFROZEN"})"); + std::string const expectedJson( + R"({"CloseResolution":19,"Method":250,)" + R"("TransactionResult":"tecFROZEN"})"); + + Json::Value jv; + if (BEAST_EXPECT(parseJSONString(goodJson, jv))) + { + // Integer values are always parsed as int, + // unless they're too big. We want a small uint. + jv["CloseResolution"] = Json::UInt(19); + STParsedJSONObject parsed("test", jv); + if (BEAST_EXPECT(parsed.object)) + { + std::string const& serialized( + to_string(parsed.object->getJson(JsonOptions::none))); + BEAST_EXPECT(serialized == expectedJson); + } + } + } + { std::string const json(R"({"CloseResolution":19,"Method":250,)" R"("TransactionResult":"terQUEUED"})"); @@ -227,6 +251,26 @@ public: } } + { + std::string const goodJson(R"({"CloseResolution":19,"Method":250,)" + R"("TransferFee":"65535"})"); + std::string const expectedJson( + R"({"CloseResolution":19,"Method":250,)" + R"("TransferFee":65535})"); + + Json::Value jv; + if (BEAST_EXPECT(parseJSONString(goodJson, jv))) + { + STParsedJSONObject parsed("test", jv); + if (BEAST_EXPECT(parsed.object)) + { + std::string const& serialized( + to_string(parsed.object->getJson(JsonOptions::none))); + BEAST_EXPECT(serialized == expectedJson); + } + } + } + { std::string const json(R"({"CloseResolution":19,"Method":250,)" R"("TransferFee":"65536"})");