From: Michael Tremer Date: Sun, 29 Dec 2024 19:09:59 +0000 (+0000) Subject: parser: Refactor unquoting strings X-Git-Tag: 0.9.30~656 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b029baea7b9ce7a440a5123cd9f5293b3f1b3628;p=pakfire.git parser: Refactor unquoting strings Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l index e6659cc41..fa78fabff 100644 --- a/src/libpakfire/parser/scanner.l +++ b/src/libpakfire/parser/scanner.l @@ -43,26 +43,21 @@ #include "grammar.h" static char* unquote(const char* input) { - size_t length = strlen(input); + char* output = NULL; - // Check whether the first character is " - if (*input != '"') - goto COPY; - - // Check whether the last characters is " - if (input[length] != '"') - goto COPY; + // Do nothing if there is no input + if (!input) + return NULL; - char* output = malloc(length - 1); + // Copy the string + output = strdup(input); if (!output) return NULL; - // Copy everything except the first and last character - snprintf(output, length - 2, "%s", input + 1); + // Unquote the string + pakfire_string_unquote(output); return output; -COPY: - return strdup(input); } // Forward declaration