From 1e2579da2c115f09ab36015c6a02fb3e767e8d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 23 Apr 2018 19:50:45 +0200 Subject: [PATCH] gdesktopappinfo: Filter out some binary names in search The executable name can be a useful bit of information to match on in searches where it differs from the name (for example because the latter is localised), but will produce surprising results where the real appli- cation is executed by a shared binary (for example interpretors like gjs or python, or sandboxes like flatpak). Address this by adding a blacklist of binary names that are ignored in search. https://bugzilla.gnome.org/show_bug.cgi?id=795488 --- gio/gdesktopappinfo.c | 20 ++++++++++++++++++++ gio/tests/desktop-app-info.c | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 869bb8feb..6844ff330 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -387,6 +387,22 @@ const gchar desktop_key_match_category[N_DESKTOP_KEYS] = { [DESKTOP_KEY_Comment] = 6 }; +/* Common prefix commands to ignore from Exec= lines */ +const char * const exec_key_match_blacklist[] = { + "bash", + "env", + "flatpak", + "gjs", + "pkexec", + "python", + "python2", + "python3", + "sh", + "wine", + "wine64", + NULL +}; + static gchar * desktop_key_get_name (guint key_id) { @@ -1089,6 +1105,10 @@ desktop_file_dir_unindexed_setup_search (DesktopFileDir *dir) /* Skip the pathname, if any */ if ((slash = strrchr (raw, '/'))) value = slash + 1; + + /* Don't match on blacklisted binaries like interpreters */ + if (g_strv_contains (exec_key_match_blacklist, value)) + value = NULL; } if (value) diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index 738b78cef..d425eb9e5 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -667,6 +667,11 @@ test_search (void) assert_search ("image viewer", "", FALSE, TRUE, NULL, NULL); assert_search ("image viewer", "", TRUE, TRUE, NULL, NULL); + /* There're flatpak apps installed as well - they should *not* match + * the "flatpak" command in the Exec= line though. + */ + assert_search ("flatpak", "", TRUE, FALSE, NULL, NULL); + /* Obvious multi-word search */ assert_search ("gno hel", "yelp.desktop\n", TRUE, TRUE, NULL, NULL);