Reject invalid match criteria with an error.

Previously, using a command like

  [con_id=foo] kill

would kill the currently focused window because while an error for
not being able to parse the con_id was logged, no further action
was taken, which caused the criterion to be ignored. In this case,
the fallback behavior of using the focused window took over.

For con_id, id and window_type we now reject incorrect values with
an error and abort the command.

fixes #2091
This commit is contained in:
Ingo Bürk
2015-12-09 13:39:08 +01:00
parent 04be42f7cd
commit 8d36f78b8e
4 changed files with 59 additions and 10 deletions

View File

@ -42,6 +42,16 @@
} \
} while (0)
/** If an error occured during parsing of the criteria, we want to exit instead
* of relying on fallback behavior. See #2091. */
#define HANDLE_INVALID_MATCH \
do { \
if (current_match->error != NULL) { \
yerror("Invalid match: %s", current_match->error); \
return; \
} \
} while (0)
/** When the command did not include match criteria (!), we use the currently
* focused container. Do not confuse this case with a command which included
* criteria but which did not match any windows. This macro has to be called in
@ -49,6 +59,8 @@
*/
#define HANDLE_EMPTY_MATCH \
do { \
HANDLE_INVALID_MATCH; \
\
if (match_is_empty(current_match)) { \
owindow *ow = smalloc(sizeof(owindow)); \
ow->con = focused; \
@ -1233,6 +1245,8 @@ void cmd_kill(I3_CMD, const char *kill_mode_str) {
return;
}
HANDLE_INVALID_MATCH;
/* check if the match is empty, not if the result is empty */
if (match_is_empty(current_match))
tree_close_con(kill_mode);