strutils::unescape(): fix handling of hexadecimal escape sequences
Hexadecimal escape sequences have no length limit and terminate at the first character that is not a valid hexadecimal digit.
This commit is contained in:
@@ -667,8 +667,9 @@ std::string unescape(const char* s)
|
||||
if (!*++s)
|
||||
break;
|
||||
int v = 0;
|
||||
for (int i = 0; i < 2 && isxdigit(*s); i++, s++)
|
||||
for (/* empty */; isxdigit(*s); s++) {
|
||||
v = v * 16 + (isdigit(*s) ? *s - '0' : 10 + tolower(*s) - 'a');
|
||||
}
|
||||
r += v;
|
||||
continue;
|
||||
|
||||
|
||||
@@ -144,6 +144,11 @@ void test_unescape()
|
||||
SG_CHECK_EQUAL(strutils::unescape("\\ \\n\\t\\x41\\117a"), " \n\tAOa");
|
||||
// Two chars: '\033' (ESC) followed by '2'
|
||||
SG_CHECK_EQUAL(strutils::unescape("\\0332"), "\0332");
|
||||
// Hex escapes have no length limit and terminate at the first character
|
||||
// that is not a valid hexadecimal digit.
|
||||
SG_CHECK_EQUAL(strutils::unescape("\\x00020|"), " |");
|
||||
SG_CHECK_EQUAL(strutils::unescape("\\xA"), "\n");
|
||||
SG_CHECK_EQUAL(strutils::unescape("\\xA-"), "\n-");
|
||||
}
|
||||
|
||||
void test_compare_versions()
|
||||
|
||||
Reference in New Issue
Block a user