Skip to content

Commit

Permalink
Use the new shescape macro for :shescape query format too
Browse files Browse the repository at this point in the history
No functional changes, just remove code duplication.
  • Loading branch information
pmatilai authored and ffesti committed Sep 24, 2021
1 parent f64ad44 commit 04de5e6
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions lib/formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,13 @@ static char * dayFormat(rpmtd td, char **emsg)
/* shell escape formatting */
static char * shescapeFormat(rpmtd td, char **emsg)
{
char * result = NULL, * dst, * src;
char *result = NULL;

if (rpmtdClass(td) == RPM_NUMERIC_CLASS) {
rasprintf(&result, "%" PRIu64, rpmtdGetNumber(td));
} else if (rpmtdClass(td) == RPM_STRING_CLASS) {
char *buf = xstrdup(rpmtdGetString(td));;

result = dst = xmalloc(strlen(buf) * 4 + 3);
*dst++ = '\'';
for (src = buf; *src != '\0'; src++) {
if (*src == '\'') {
*dst++ = '\'';
*dst++ = '\\';
*dst++ = '\'';
*dst++ = '\'';
} else {
*dst++ = *src;
}
}
*dst++ = '\'';
*dst = '\0';
free(buf);
const char *args[] = { rpmtdGetString(td), NULL };
rpmExpandThisMacro(NULL, "shescape", (ARGV_const_t)args, &result, 0);
} else {
*emsg = xstrdup(_("(invalid type)"));
}
Expand Down

0 comments on commit 04de5e6

Please sign in to comment.