Skip to content

Commit

Permalink
app-info: Use xdp-utils quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
swick committed Sep 12, 2024
1 parent 2a8f19b commit a5f7874
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions src/xdp-app-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,32 +648,6 @@ xdp_app_info_remap_path (XdpAppInfo *app_info,
return g_strdup (path);
}

static gboolean
needs_quoting (const char *arg)
{
while (*arg != 0)
{
char c = *arg;
if (!g_ascii_isalnum (c) &&
!(c == '-' || c == '/' || c == '~' ||
c == ':' || c == '.' || c == '_' ||
c == '=' || c == '@'))
return TRUE;
arg++;
}
return FALSE;
}

static char *
maybe_quote (const char *arg,
gboolean quote_escape)
{
if (!quote_escape || !needs_quoting (arg))
return g_strdup (arg);
else
return g_shell_quote (arg);
}

static char **
rewrite_commandline (XdpAppInfo *app_info,
const char * const *commandline,
Expand All @@ -690,7 +664,7 @@ rewrite_commandline (XdpAppInfo *app_info,
int i;
args = g_ptr_array_new_with_free_func (g_free);
for (i = 0; commandline && commandline[i]; i++)
g_ptr_array_add (args, maybe_quote (commandline[i], quote_escape));
g_ptr_array_add (args, xdp_maybe_quote (commandline[i], quote_escape));
g_ptr_array_add (args, NULL);
return (char **)g_ptr_array_free (g_steal_pointer (&args), FALSE);
}
Expand All @@ -705,7 +679,7 @@ rewrite_commandline (XdpAppInfo *app_info,
int i;
g_autofree char *quoted_command = NULL;

quoted_command = maybe_quote (commandline[0], quote_escape);
quoted_command = xdp_maybe_quote (commandline[0], quote_escape);

g_ptr_array_add (args, g_strdup_printf ("--command=%s", quoted_command));

Expand All @@ -718,7 +692,7 @@ rewrite_commandline (XdpAppInfo *app_info,
g_ptr_array_add (args, g_strdup (priv->id));

for (i = 1; commandline[i]; i++)
g_ptr_array_add (args, maybe_quote (commandline[i], quote_escape));
g_ptr_array_add (args, xdp_maybe_quote (commandline[i], quote_escape));
}
else if (quote_escape)
g_ptr_array_add (args, g_shell_quote (priv->id));
Expand Down

0 comments on commit a5f7874

Please sign in to comment.