From: Michael Tremer Date: Thu, 25 Feb 2021 16:51:40 +0000 (+0000) Subject: parser: Fixup readline X-Git-Tag: 0.9.28~1285^2~690 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f33ee78e6dbced9b2f63c1af3c4a804ed9dedca;p=pakfire.git parser: Fixup readline This could read into the next line when a line was empty Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 83700d5a8..4022190e8 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -56,6 +56,7 @@ void pakfire_partition_string(const char* s, const char* delim, char** s1, char* #ifdef PAKFIRE_PRIVATE int pakfire_string_endswith(const char* s, const char* suffix); +char* pakfire_lstrip(const char* s); #endif diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l index 71715a087..b2fd90d60 100644 --- a/src/libpakfire/parser/scanner.l +++ b/src/libpakfire/parser/scanner.l @@ -37,6 +37,7 @@ int num_lines; #include #include +#include #include "grammar.h" @@ -210,15 +211,12 @@ scriptlet script(let)? yy_push_state(NOKEYWORD); } -{whitespace} { - // consume any leading whitespace - } -[^ \t].*$ { +.*$ { // Return to caller yy_pop_state(); // Copy the entire string - yylval.string = strdup(yytext); + yylval.string = pakfire_lstrip(yytext); return T_STRING; } diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 38c0a71ba..e4eac58fb 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -43,6 +43,16 @@ int pakfire_string_endswith(const char* s, const char* suffix) { return !strcmp(s + strlen(s) - strlen(suffix), suffix); } +char* pakfire_lstrip(const char* s) { + while (*s && isspace(*s)) + s++; + + if (s) + return strdup(s); + + return NULL; +} + char* pakfire_format_size(double size) { char string[STRING_SIZE]; const char* units[] = {" ", "k", "M", "G", "T", NULL};