From ad1b3d13c62c8ca1e61a34a6ade9426a81429c7e Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Tue, 28 Nov 2023 11:31:32 +0100 Subject: [PATCH] Make shescape escape all arguments and not just the first one This makes the %shescape macro work use all arguments like we already do in the %quote macro. I.e.: %{shescpae:hello world} -> 'hello world' %{shescpae hello world} -> 'hello' 'world' --- rpmio/macro.c | 19 ++++++++++++------- tests/rpmmacro.at | 12 ++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index b02319c63..6780bb36a 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1164,15 +1164,20 @@ static void doVerbose(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *par static void doShescape(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed) { - rpmMacroBufAppend(mb, '\''); - for (const char *s = argv[1]; *s != '\0'; s++) { - if (*s == '\'') { - rpmMacroBufAppendStr(mb, "'\\''"); - } else { - rpmMacroBufAppend(mb, *s); + int i; + for (i = 1 ; argv[i]; i++) { + if (i != 1) + rpmMacroBufAppend(mb, ' '); + rpmMacroBufAppend(mb, '\''); + for (const char *s = argv[i]; *s != '\0'; s++) { + if (*s == '\'') { + rpmMacroBufAppendStr(mb, "'\\''"); + } else { + rpmMacroBufAppend(mb, *s); + } } + rpmMacroBufAppend(mb, '\''); } - rpmMacroBufAppend(mb, '\''); } static uint64_t getmem_total(void) diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at index 41b6c5076..0ebcc050c 100644 --- a/tests/rpmmacro.at +++ b/tests/rpmmacro.at @@ -1101,6 +1101,18 @@ runroot rpm \ []) RPMTEST_CLEANUP +AT_SETUP([%shescape macro with multiple arguments]) +AT_KEYWORDS([macros]) +RPMTEST_CHECK([ +runroot rpm \ + --eval "%{shescape foo bar's}" +], +[0], +['foo' 'bar'\''s' +], +[]) + +RPMTEST_CLEANUP AT_SETUP([macro with a line starting by "{"]) AT_KEYWORDS([macros]) RPMTEST_CHECK([