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'
This commit is contained in:
Michael Schroeder 2023-11-28 11:31:32 +01:00 committed by Panu Matilainen
parent 014b09de6f
commit ad1b3d13c6
2 changed files with 24 additions and 7 deletions

View File

@ -1164,8 +1164,12 @@ 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)
{
int i;
for (i = 1 ; argv[i]; i++) {
if (i != 1)
rpmMacroBufAppend(mb, ' ');
rpmMacroBufAppend(mb, '\'');
for (const char *s = argv[1]; *s != '\0'; s++) {
for (const char *s = argv[i]; *s != '\0'; s++) {
if (*s == '\'') {
rpmMacroBufAppendStr(mb, "'\\''");
} else {
@ -1173,6 +1177,7 @@ static void doShescape(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *pa
}
}
rpmMacroBufAppend(mb, '\'');
}
}
static uint64_t getmem_total(void)

View File

@ -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([