cmd: fix input/output unstripped definition quotes

With the following config:

    set $abc "wayland wayland "
    set $def "0:0:wayland-seat0"

The following command would fail to be executed:

    swaymsg -- output '$abc' scale 2
    swaymsg -- input '$def' repeat_rate 2

The definition `$abc` is replaced with its content, including the quotes,
which fails to match real output names. Same for `$def`

We now strip quotes early in the output command.

The behaviour was inconsistent between config_command() and execute_command().
* config_command() strips quotes before do_var_replacement() and also after,
  under some conditions.
* execute_command() strips them only before.

execute_command() is run after receiving swaymsg command hence the
failing example mentioned above.

Since we now strip quotes in cmd_output and cmd_input we prevent
config_command() from stripping them twice.
This commit is contained in:
Paul Riou 2021-01-06 00:48:19 +00:00
parent 97adba0516
commit 7461473918
3 changed files with 17 additions and 0 deletions

View file

@ -403,6 +403,8 @@ struct cmd_results *config_command(char *exec, char **new_block) {
&& handler->handle != cmd_bindswitch
&& handler->handle != cmd_set
&& handler->handle != cmd_for_window
&& handler->handle != cmd_output
&& handler->handle != cmd_input
&& (*argv[i] == '\"' || *argv[i] == '\'')) {
strip_quotes(argv[i]);
}

View file

@ -51,6 +51,13 @@ struct cmd_results *cmd_input(int argc, char **argv) {
return error;
}
// Commands from config_command() & execute_command() don't handle quotes the same way
for (int i = 0; i < argc; ++i) {
if (*argv[i] == '\"' || *argv[i] == '\'') {
strip_quotes(argv[i]);
}
}
sway_log(SWAY_DEBUG, "entering input block: %s", argv[0]);
config->handler_context.input_config = new_input_config(argv[0]);

View file

@ -2,6 +2,7 @@
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/output.h"
#include "stringop.h"
#include "list.h"
#include "log.h"
@ -39,6 +40,13 @@ struct cmd_results *cmd_output(int argc, char **argv) {
"Refusing to configure the no op output");
}
// Commands from config_command() & execute_command() don't handle quotes the same way
for (int i = 0; i < argc; ++i) {
if (*argv[i] == '\"' || *argv[i] == '\'') {
strip_quotes(argv[i]);
}
}
struct output_config *output = NULL;
if (strcmp(argv[0], "-") == 0 || strcmp(argv[0], "--") == 0) {
if (config->reading) {