From: Michael Stapelberg Date: Thu, 12 May 2011 05:09:06 +0000 (+0200) Subject: Bugfix: Correct string/quoted string parsing for the commands exec, workspace, nop... X-Git-Tag: tree-pr3~39 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=94646190aaddc1285d06cd7f90721230246caa85;p=i3%2Fi3 Bugfix: Correct string/quoted string parsing for the commands exec, workspace, nop, restore and mark (Thanks SardemFF7) Fixes: #380 --- diff --git a/src/cmdparse.l b/src/cmdparse.l index ebd466af..f07420d3 100644 --- a/src/cmdparse.l +++ b/src/cmdparse.l @@ -65,16 +65,16 @@ EOL (\r?\n) cmdyycolumn = 1; } -[^\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; } [ \t]* { BEGIN(WANT_STRING); return WHITESPACE; } -\"[^\"]+\" { +\"[^\"]+\" { BEGIN(INITIAL); /* strip quotes */ char *copy = sstrdup(yytext+1); copy[strlen(copy)-1] = '\0'; cmdyylval.string = copy; return STR; - } + } +[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; } [ \t]* { return WHITESPACE; } attach { return TOK_ATTACH; } diff --git a/testcases/t/20-multiple-cmds.t b/testcases/t/20-multiple-cmds.t index 379d08ee..784329fb 100644 --- a/testcases/t/20-multiple-cmds.t +++ b/testcases/t/20-multiple-cmds.t @@ -30,6 +30,27 @@ multiple_cmds("kill\t ;\tkill"); multiple_cmds("kill\t ;\t kill"); multiple_cmds("kill \t ; \t kill"); +##################################################################### +# test if un-quoted strings are handled correctly +##################################################################### + +$tmp = fresh_workspace; +cmd 'open'; +my $unused = get_unused_workspace; +ok(!($unused ~~ @{get_workspace_names()}), 'workspace does not exist yet'); +cmd "move workspace $unused; nop parser test"; +ok(($unused ~~ @{get_workspace_names()}), 'workspace exists after moving'); + +##################################################################### +# quote the workspace name and use a ; (command separator) in its name +##################################################################### + +$unused = get_unused_workspace; +$unused .= ';a'; +ok(!($unused ~~ @{get_workspace_names()}), 'workspace does not exist yet'); +cmd qq|move workspace "$unused"; nop parser test|; +ok(($unused ~~ @{get_workspace_names()}), 'workspace exists after moving'); + # TODO: need a non-invasive command before implementing a test which uses ',' done_testing;