Fixes.
h3rald h3rald@h3rald.com
Thu, 02 Jan 2025 20:29:15 +0000
1 files changed,
30 insertions(+),
19 deletions(-)
jump to
M
src/utils.c
→
src/utils.c
@@ -386,8 +386,7 @@
return 4; // Default to 4 bytes if no smaller size is found. } -char *hex_unescape_string(const char *input) -{ +char *hex_unescape_string(const char *input) { if (input == NULL) { return NULL; // Handle null input }@@ -403,24 +402,35 @@ const char *src = input;
char *dst = output; while (*src) { - if (*src == '\\' && *(src + 1)) { - switch (*(src + 1)) { - case 'n': *dst = '\n'; break; - case 't': *dst = '\t'; break; - case 'r': *dst = '\r'; break; - case '\\': *dst = '\\'; break; - case '\'': *dst = '\''; break; - case '\"': *dst = '\"'; break; - case 'b': *dst = '\b'; break; - case 'f': *dst = '\f'; break; - case 'v': *dst = '\v'; break; - default: - // If not a valid escape, copy the backslash and next character - *dst++ = *src; - *dst = *(src + 1); + if (*src == '\\') { + if (*(src + 1) == '\\') { + // Handle escaped backslash + *dst = '\\'; + src += 2; // Skip both backslashes + if (*(src + 2)) { + *dst = *(src + 2); + src += 1; + } + } else { + // Handle other escape sequences + switch (*(src + 1)) { + case 'n': *dst = '\n'; break; + case 't': *dst = '\t'; break; + case 'r': *dst = '\r'; break; + case '\'': *dst = '\''; break; + case '\"': *dst = '\"'; break; + case 'b': *dst = '\b'; break; + case 'f': *dst = '\f'; break; + case 'v': *dst = '\v'; break; + default: + // Unknown escape sequence, copy as-is + *dst++ = '\\'; + *dst = *(src + 1); + } + src += 2; // Skip backslash and escape character } - src += 2; // Skip the escape sequence } else { + // Copy normal characters *dst = *src; src++; }@@ -429,4 +439,5 @@ }
*dst = '\0'; // Null-terminate the output string return output; -} +} +