mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge bitcoin/bitcoin#22859: Replace uses of boost::trim* with locale-independent alternatives (#18130 rebased)
696c76d660
tests: Add TrimString(...) tests (practicalswift)4bf18b089e
Replace use of boost::trim_right with locale-independent TrimString (Ben Woosley)93551862a1
Replace use of boost::trim use with locale-independent TrimString (Ben Woosley) Pull request description: This is [#18130 rebased](https://github.com/bitcoin/bitcoin/pull/18130#issuecomment-900158759). > `TrimString` is an existing alternative. > Note `TrimString` uses `" \f\n\r\t\v"` as the pattern, which is consistent with the default behavior of `std::isspace`. See: https://en.cppreference.com/w/cpp/string/byte/isspace ACKs for top commit: jb55: utACK696c76d660
practicalswift: ACK696c76d660
jonatack: ACK696c76d660
theStack: Code-review ACK696c76d660
Tree-SHA512: 6a70e3777602dfa65a60353e5c6874eb951e4a806844cd4bdaa4237cad980a4f61ec205defc05a29f9707776835975838f6cc635259c42adfe37ceb02ba9358d
This commit is contained in:
commit
6490a3ef6c
4 changed files with 20 additions and 8 deletions
|
@ -772,9 +772,7 @@ static std::string readStdin()
|
|||
if (ferror(stdin))
|
||||
throw std::runtime_error("error reading stdin");
|
||||
|
||||
boost::algorithm::trim_right(ret);
|
||||
|
||||
return ret;
|
||||
return TrimString(ret);
|
||||
}
|
||||
|
||||
static int CommandLineRawTx(int argc, char* argv[])
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <rpc/protocol.h>
|
||||
#include <rpc/server.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
#include <walletinitinterface.h>
|
||||
|
@ -22,7 +23,7 @@
|
|||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <boost/algorithm/string.hpp> // boost::trim
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
/** WWW-Authenticate to present with 401 Unauthorized response */
|
||||
static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";
|
||||
|
@ -130,8 +131,7 @@ static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUserna
|
|||
return false;
|
||||
if (strAuth.substr(0, 6) != "Basic ")
|
||||
return false;
|
||||
std::string strUserPass64 = strAuth.substr(6);
|
||||
boost::trim(strUserPass64);
|
||||
std::string strUserPass64 = TrimString(strAuth.substr(6));
|
||||
std::string strUserPass = DecodeBase64(strUserPass64);
|
||||
|
||||
if (strUserPass.find(':') != std::string::npos)
|
||||
|
|
|
@ -173,6 +173,22 @@ BOOST_AUTO_TEST_CASE(util_Join)
|
|||
BOOST_CHECK_EQUAL(Join<std::string>({"foo", "bar"}, ", ", op_upper), "FOO, BAR");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_TrimString)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(TrimString(" foo bar "), "foo bar");
|
||||
BOOST_CHECK_EQUAL(TrimString("\t \n \n \f\n\r\t\v\tfoo \n \f\n\r\t\v\tbar\t \n \f\n\r\t\v\t\n "), "foo \n \f\n\r\t\v\tbar");
|
||||
BOOST_CHECK_EQUAL(TrimString("\t \n foo \n\tbar\t \n "), "foo \n\tbar");
|
||||
BOOST_CHECK_EQUAL(TrimString("\t \n foo \n\tbar\t \n ", "fobar"), "\t \n foo \n\tbar\t \n ");
|
||||
BOOST_CHECK_EQUAL(TrimString("foo bar"), "foo bar");
|
||||
BOOST_CHECK_EQUAL(TrimString("foo bar", "fobar"), " ");
|
||||
BOOST_CHECK_EQUAL(TrimString(std::string("\0 foo \0 ", 8)), std::string("\0 foo \0", 7));
|
||||
BOOST_CHECK_EQUAL(TrimString(std::string(" foo ", 5)), std::string("foo", 3));
|
||||
BOOST_CHECK_EQUAL(TrimString(std::string("\t\t\0\0\n\n", 6)), std::string("\0\0", 2));
|
||||
BOOST_CHECK_EQUAL(TrimString(std::string("\x05\x04\x03\x02\x01\x00", 6)), std::string("\x05\x04\x03\x02\x01\x00", 6));
|
||||
BOOST_CHECK_EQUAL(TrimString(std::string("\x05\x04\x03\x02\x01\x00", 6), std::string("\x05\x04\x03\x02\x01", 5)), std::string("\0", 1));
|
||||
BOOST_CHECK_EQUAL(TrimString(std::string("\x05\x04\x03\x02\x01\x00", 6), std::string("\x05\x04\x03\x02\x01\x00", 6)), "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_FormatParseISO8601DateTime)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(FormatISO8601DateTime(1317425777), "2011-09-30T23:36:17Z");
|
||||
|
|
|
@ -39,10 +39,8 @@ export LC_ALL=C
|
|||
|
||||
KNOWN_VIOLATIONS=(
|
||||
"src/bitcoin-tx.cpp.*stoul"
|
||||
"src/bitcoin-tx.cpp.*trim_right"
|
||||
"src/dbwrapper.cpp.*stoul"
|
||||
"src/dbwrapper.cpp:.*vsnprintf"
|
||||
"src/httprpc.cpp.*trim"
|
||||
"src/node/blockstorage.cpp:.*atoi"
|
||||
"src/qt/rpcconsole.cpp:.*atoi"
|
||||
"src/rest.cpp:.*strtol"
|
||||
|
|
Loading…
Add table
Reference in a new issue