Skip to content

Commit

Permalink
Make shescape escape all arguments and not just the first one
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
mlschroe authored and pmatilai committed Dec 8, 2023
1 parent 014b09d commit ad1b3d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 12 additions & 7 deletions rpmio/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/rpmmacro.at
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit ad1b3d1

Please sign in to comment.