From 74614739183fda11e9ba0b8d1ea2c7cec1c6350a Mon Sep 17 00:00:00 2001 From: Paul Riou Date: Wed, 6 Jan 2021 00:48:19 +0000 Subject: [PATCH] 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. --- sway/commands.c | 2 ++ sway/commands/input.c | 7 +++++++ sway/commands/output.c | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/sway/commands.c b/sway/commands.c index fe1e98b53..0cc16f775 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -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]); } diff --git a/sway/commands/input.c b/sway/commands/input.c index c9bb8e06a..f0414bc66 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -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]); diff --git a/sway/commands/output.c b/sway/commands/output.c index 5186a2ba1..d28387a0c 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -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) {