mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
fix CTID in tx command returns invalidParams on lowercase hex (#5049)
* fix CTID in tx command returns invalidParams on lowercase hex * test mixed case and change auto to explicit type * add header cctype because std::tolower is called * remove unused local variable * change test case comment from 'lowercase' to 'mixed case' --------- Co-authored-by: Zack Brunson <Zshooter@gmail.com>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/protocol/serialize.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
|
||||
@@ -671,6 +672,47 @@ class Transaction_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(jrr[jss::hash]);
|
||||
}
|
||||
|
||||
// test querying with mixed case ctid
|
||||
{
|
||||
Env env{*this, makeNetworkConfig(11111)};
|
||||
std::uint32_t const netID = env.app().config().NETWORK_ID;
|
||||
|
||||
Account const alice = Account("alice");
|
||||
Account const bob = Account("bob");
|
||||
|
||||
std::uint32_t const startLegSeq = env.current()->info().seq;
|
||||
env.fund(XRP(10000), alice, bob);
|
||||
env(pay(alice, bob, XRP(10)));
|
||||
env.close();
|
||||
|
||||
std::string const ctid = *RPC::encodeCTID(startLegSeq, 0, netID);
|
||||
auto isUpper = [](char c) { return std::isupper(c) != 0; };
|
||||
|
||||
// Verify that there are at least two upper case letters in ctid and
|
||||
// test a mixed case
|
||||
if (BEAST_EXPECT(
|
||||
std::count_if(ctid.begin(), ctid.end(), isUpper) > 1))
|
||||
{
|
||||
// Change the first upper case letter to lower case.
|
||||
std::string mixedCase = ctid;
|
||||
{
|
||||
auto const iter = std::find_if(
|
||||
mixedCase.begin(), mixedCase.end(), isUpper);
|
||||
*iter = std::tolower(*iter);
|
||||
}
|
||||
BEAST_EXPECT(ctid != mixedCase);
|
||||
|
||||
Json::Value jsonTx;
|
||||
jsonTx[jss::binary] = false;
|
||||
jsonTx[jss::ctid] = mixedCase;
|
||||
jsonTx[jss::id] = 1;
|
||||
Json::Value const jrr =
|
||||
env.rpc("json", "tx", to_string(jsonTx))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::ctid] == ctid);
|
||||
BEAST_EXPECT(jrr[jss::hash]);
|
||||
}
|
||||
}
|
||||
|
||||
// test that if the network is 65535 the ctid is not in the response
|
||||
{
|
||||
Env env{*this, makeNetworkConfig(65535)};
|
||||
|
||||
@@ -63,7 +63,7 @@ decodeCTID(const T ctid) noexcept
|
||||
if (ctidString.length() != 16)
|
||||
return {};
|
||||
|
||||
if (!boost::regex_match(ctidString, boost::regex("^[0-9A-F]+$")))
|
||||
if (!boost::regex_match(ctidString, boost::regex("^[0-9A-Fa-f]+$")))
|
||||
return {};
|
||||
|
||||
ctidValue = std::stoull(ctidString, nullptr, 16);
|
||||
|
||||
Reference in New Issue
Block a user