summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2018-06-22 11:54:05 +0200
committerBenjamin Berg <bberg@redhat.com>2018-06-22 11:58:42 +0200
commit660dde8a2ae92a393a2141ea10c6fbf36ea94240 (patch)
tree526d11c930d7a7992678badd9ba9d9c66bca138f
parent61d36ccc196853efa2ce3cce75d9e0f81ee790f3 (diff)
downloadgnome-settings-daemon-benzea/media-keys-escape-cmdline.tar.gz
media-keys: Escape custom command for executionbenzea/media-keys-escape-cmdline
g_app_info_create_from_commandline interprets the % character of commands that are entered by the user. So escape all % characters by doubling them so that they are not stripped from the resulting command line. This fixes issue #34
-rw-r--r--plugins/media-keys/gsd-media-keys-manager.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index ee6ecbf3..42b88482 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -883,8 +883,25 @@ execute (GsdMediaKeysManager *manager,
gint64 timestamp)
{
GAppInfo *app_info;
+ g_autofree gchar *escaped = NULL;
+ gchar *p;
+
+ /* Escape all % characters as g_app_info_creat_from_commandline will
+ * try to interpret them otherwise. */
+ escaped = g_malloc (strlen (cmd) * 2 + 1);
+ p = escaped;
+ while (*cmd) {
+ *p = *cmd;
+ p++;
+ if (*cmd == '%') {
+ *p = '%';
+ p++;
+ }
+ cmd++;
+ }
+ *p = '\0';
- app_info = g_app_info_create_from_commandline (cmd, NULL, G_APP_INFO_CREATE_NONE, NULL);
+ app_info = g_app_info_create_from_commandline (escaped, NULL, G_APP_INFO_CREATE_NONE, NULL);
launch_app (manager, app_info, timestamp);
g_object_unref (app_info);
}