From 665b4715000e4f6b55db0e23ca100c56f3be4455 Mon Sep 17 00:00:00 2001 From: OmegaPhil Date: Fri, 18 Apr 2014 08:25:00 -0400 Subject: [PATCH] ItemEditor: Fix bad command validation When the Exec line has multiple components, we need to parse it and only check the first one. https://bugzilla.gnome.org/show_bug.cgi?id=728372 --- Alacarte/ItemEditor.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Alacarte/ItemEditor.py b/Alacarte/ItemEditor.py index 3b48324..e89c0ff 100644 --- Alacarte/ItemEditor.py +++ Alacarte/ItemEditor.py @@ -179,10 +179,24 @@ class LauncherEditor(ItemEditor): self.builder.get_object('name-entry').connect('changed', self.resync_validity) self.builder.get_object('exec-entry').connect('changed', self.resync_validity) + def exec_line_is_valid(self, exec_text): + try: + # Attempting to parse command - commands are not simply program names or paths... Errors are raised for blank or invalid input (e.g. missing closing quote) + result = GLib.shell_parse_argv(exec_text) + if result[0]: + # Parsing succeeded - making sure program (first part of the command) is in the path + command = result[1][0] + return (GLib.find_program_in_path(command) is not None) + else: + # Parsing failure, but not reported via raised GError? + return False + except GLib.GError: + return False + def resync_validity(self, *args): name_text = self.builder.get_object('name-entry').get_text() exec_text = self.builder.get_object('exec-entry').get_text() - valid = (name_text != "" and GLib.find_program_in_path(exec_text) is not None) + valid = (name_text != "" and self.exec_line_is_valid(exec_text)) self.builder.get_object('ok').set_sensitive(valid) def load(self): -- 2.18.1 From ca7d05cc060e0a31039bb8186da35058f6b02cd1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 18 Apr 2014 10:08:27 -0400 Subject: [PATCH] ItemEditor: Clean up validation logic a tiny bit When g_shell_parse_argv returns FALSE, it means an error has been thrown, so we don't need to check it ourselves. --- Alacarte/ItemEditor.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Alacarte/ItemEditor.py b/Alacarte/ItemEditor.py index e89c0ff..7b9d47a 100644 --- Alacarte/ItemEditor.py +++ Alacarte/ItemEditor.py @@ -181,15 +181,11 @@ class LauncherEditor(ItemEditor): def exec_line_is_valid(self, exec_text): try: - # Attempting to parse command - commands are not simply program names or paths... Errors are raised for blank or invalid input (e.g. missing closing quote) - result = GLib.shell_parse_argv(exec_text) - if result[0]: - # Parsing succeeded - making sure program (first part of the command) is in the path - command = result[1][0] - return (GLib.find_program_in_path(command) is not None) - else: - # Parsing failure, but not reported via raised GError? - return False + success, parsed = GLib.shell_parse_argv(exec_text) + + # Make sure program (first part of the command) is in the path + command = parsed[0] + return (GLib.find_program_in_path(command) is not None) except GLib.GError: return False -- 2.18.1