Skip to content

Commit d9ccce2

Browse files
authored
Allow common process_escapes to handle \x sequences (#3928)
* Allow common process_escapes to handle \x sequences * Fix edge case when second hex digit is NUL
1 parent bb60fd0 commit d9ccce2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

common/common.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ void process_escapes(std::string& input) {
9090
case '\'': input[output_idx++] = '\''; break;
9191
case '\"': input[output_idx++] = '\"'; break;
9292
case '\\': input[output_idx++] = '\\'; break;
93+
case 'x':
94+
// Handle \x12, etc
95+
if (input_idx + 2 < input_len) {
96+
const char x[3] = { input[input_idx + 1], input[input_idx + 2], 0 };
97+
char *err_p = nullptr;
98+
const long val = std::strtol(x, &err_p, 16);
99+
if (err_p == x + 2) {
100+
input_idx += 2;
101+
input[output_idx++] = char(val);
102+
break;
103+
}
104+
// Intentionally fall through to default.
105+
}
93106
default: input[output_idx++] = '\\';
94107
input[output_idx++] = input[input_idx]; break;
95108
}

0 commit comments

Comments
 (0)