Merge pull request #11104

aa94914 epee: fix hex separator handling (questfever)

ACKs: selsta, jpk68
This commit is contained in:
tobtoht
2026-08-19 11:23:43 +00:00
2 changed files with 8 additions and 2 deletions
+5 -2
View File
@@ -134,7 +134,7 @@ namespace epee
// should we include a specific character
auto include = [](char input) {
// 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
@@ -153,7 +153,7 @@ namespace epee
// convert a single hex character to an unsigned integer
auto char_to_int = [](const char *input) {
switch (std::tolower(*input)) {
switch (std::tolower(static_cast<unsigned char>(*input))) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
@@ -184,6 +184,9 @@ namespace epee
// convert two matching characters to int
auto high = char_to_int(data++);
while (data != src.end() && !include(*data)) {
++data;
}
auto low = char_to_int(data++);
result.push_back(high << 4 | low);
+3
View File
@@ -1221,6 +1221,9 @@ TEST(HexLocale, String)
hex.assign("00:ff 0f:f0");
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");
EXPECT_EQ(source, epee::from_hex_locale::to_vector(boost::string_ref{hex.data(), hex.size() - 2}));
}