mirror of
https://github.com/wownero/wownero.git
synced 2026-11-17 22:04:13 +01:00
epee: fix hex separator handling
This commit is contained in:
@@ -134,7 +134,7 @@ namespace epee
|
|||||||
// should we include a specific character
|
// should we include a specific character
|
||||||
auto include = [](char input) {
|
auto include = [](char input) {
|
||||||
// we ignore spaces and colons
|
// we ignore spaces and colons
|
||||||
return !std::isspace(input) && input != ':';
|
return !std::isspace(static_cast<unsigned char>(input)) && input != ':';
|
||||||
};
|
};
|
||||||
|
|
||||||
// the number of relevant characters to decode
|
// the number of relevant characters to decode
|
||||||
@@ -153,7 +153,7 @@ namespace epee
|
|||||||
|
|
||||||
// convert a single hex character to an unsigned integer
|
// convert a single hex character to an unsigned integer
|
||||||
auto char_to_int = [](const char *input) {
|
auto char_to_int = [](const char *input) {
|
||||||
switch (std::tolower(*input)) {
|
switch (std::tolower(static_cast<unsigned char>(*input))) {
|
||||||
case '0': return 0;
|
case '0': return 0;
|
||||||
case '1': return 1;
|
case '1': return 1;
|
||||||
case '2': return 2;
|
case '2': return 2;
|
||||||
@@ -184,6 +184,9 @@ namespace epee
|
|||||||
|
|
||||||
// convert two matching characters to int
|
// convert two matching characters to int
|
||||||
auto high = char_to_int(data++);
|
auto high = char_to_int(data++);
|
||||||
|
while (data != src.end() && !include(*data)) {
|
||||||
|
++data;
|
||||||
|
}
|
||||||
auto low = char_to_int(data++);
|
auto low = char_to_int(data++);
|
||||||
|
|
||||||
result.push_back(high << 4 | low);
|
result.push_back(high << 4 | low);
|
||||||
|
|||||||
@@ -1221,6 +1221,9 @@ TEST(HexLocale, String)
|
|||||||
hex.assign("00:ff 0f:f0");
|
hex.assign("00:ff 0f:f0");
|
||||||
EXPECT_EQ(source, epee::from_hex_locale::to_vector(hex));
|
EXPECT_EQ(source, epee::from_hex_locale::to_vector(hex));
|
||||||
|
|
||||||
|
hex.assign("0:0 f f 0:f f:0");
|
||||||
|
EXPECT_EQ(source, epee::from_hex_locale::to_vector(hex));
|
||||||
|
|
||||||
hex.append("f0");
|
hex.append("f0");
|
||||||
EXPECT_EQ(source, epee::from_hex_locale::to_vector(boost::string_ref{hex.data(), hex.size() - 2}));
|
EXPECT_EQ(source, epee::from_hex_locale::to_vector(boost::string_ref{hex.data(), hex.size() - 2}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user