From 2a215fd7e22f5d8e9f82fb5a1d610e56afa99fe7 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 11 Sep 2011 22:51:59 +0100 Subject: [PATCH] Bugfix: Ignore for_window commands with empty (invalid) criteria (+test) (Thanks aksr) --- src/cfgparse.y | 4 ++++ testcases/t/65-for_window.t | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/cfgparse.y b/src/cfgparse.y index 5b2b4b5c..10ca48cc 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -659,6 +659,10 @@ bindsym: for_window: TOK_FOR_WINDOW match command { + if (match_is_empty(¤t_match)) { + ELOG("Match is empty, ignoring this for_window statement\n"); + break; + } printf("\t should execute command %s for the criteria mentioned above\n", $3); Assignment *assignment = scalloc(sizeof(Assignment)); assignment->type = A_COMMAND; diff --git a/testcases/t/65-for_window.t b/testcases/t/65-for_window.t index 2fb85dfa..fb4c2812 100644 --- a/testcases/t/65-for_window.t +++ b/testcases/t/65-for_window.t @@ -313,4 +313,41 @@ is($content[0]->{border}, 'none', 'no border'); exit_gracefully($process->pid); +############################################################## +# 7: check that invalid criteria don’t end up matching all windows +############################################################## + +# this configuration is broken because "asdf" is not a valid integer +# the for_window should therefore recognize this error and don’t add the +# assignment +$config = <root->create_child( + class => WINDOW_CLASS_INPUT_OUTPUT, + rect => [ 0, 0, 30, 30 ], + background_color => '#00ff00', +); + +$window->_create; + +set_wm_class($window->id, 'bar', 'foo'); +$window->name('usethis'); +$window->map; +sleep 0.25; + +@content = @{get_ws_content($tmp)}; +cmp_ok(@content, '==', 1, 'one node on this workspace now'); +is($content[0]->{border}, 'normal', 'normal border'); + +exit_gracefully($process->pid); + + done_testing;