aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sway/commands/move.c7
-rw-r--r--sway/commands/rename.c8
-rw-r--r--sway/commands/workspace.c7
-rw-r--r--sway/tree/workspace.c25
4 files changed, 29 insertions, 18 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index f5eb9124..33d1ee4a 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE 500
+#include <ctype.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
@@ -124,7 +125,11 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
return cmd_results_new(CMD_INVALID, "move",
expected_syntax);
}
- ws_name = strdup(argv[3]);
+ if (!isdigit(argv[3][0])) {
+ return cmd_results_new(CMD_INVALID, "move",
+ "Invalid workspace number '%s'", argv[3]);
+ }
+ ws_name = join_args(argv + 3, argc - 3);
ws = workspace_by_number(ws_name);
} else {
ws_name = join_args(argv + 2, argc - 2);
diff --git a/sway/commands/rename.c b/sway/commands/rename.c
index c69bbdac..21d2aa64 100644
--- a/sway/commands/rename.c
+++ b/sway/commands/rename.c
@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE 500
+#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "log.h"
@@ -34,6 +35,10 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
}
} else if (strcasecmp(argv[1], "number") == 0) {
// 'rename workspace number x to new_name'
+ if (!isdigit(argv[2][0])) {
+ return cmd_results_new(CMD_INVALID, "rename",
+ "Invalid workspace number '%s'", argv[2]);
+ }
workspace = workspace_by_number(argv[2]);
while (argn < argc && strcasecmp(argv[argn], "to") != 0) {
++argn;
@@ -67,7 +72,8 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
strcasecmp(new_name, "next_on_output") == 0 ||
strcasecmp(new_name, "prev_on_output") == 0 ||
strcasecmp(new_name, "back_and_forth") == 0 ||
- strcasecmp(new_name, "current") == 0) {
+ strcasecmp(new_name, "current") == 0 ||
+ strcasecmp(new_name, "number") == 0) {
free(new_name);
return cmd_results_new(CMD_INVALID, "rename",
"Cannot use special workspace name '%s'", argv[argn]);
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index f5558bb4..ceb4cd6e 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE 500
+#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
@@ -60,9 +61,13 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
struct sway_container *ws = NULL;
if (strcasecmp(argv[0], "number") == 0) {
if (argc < 2) {
- cmd_results_new(CMD_INVALID, "workspace",
+ return cmd_results_new(CMD_INVALID, "workspace",
"Expected workspace number");
}
+ if (!isdigit(argv[1][0])) {
+ return cmd_results_new(CMD_INVALID, "workspace",
+ "Invalid workspace number '%s'", argv[1]);
+ }
if (!(ws = workspace_by_number(argv[1]))) {
char *name = join_args(argv + 1, argc - 1);
ws = workspace_create(NULL, name);
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index b7090de6..a6d1870c 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -82,11 +82,6 @@ struct sway_container *workspace_create(struct sway_container *output,
}
char *prev_workspace_name = NULL;
-struct workspace_by_number_data {
- int len;
- const char *cset;
- const char *name;
-};
void next_name_map(struct sway_container *ws, void *data) {
int *count = data;
@@ -154,7 +149,7 @@ static void workspace_name_from_binding(const struct sway_binding * binding,
wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target);
// Make sure the workspace number doesn't already exist
- if (workspace_by_number(_target)) {
+ if (isdigit(_target[0]) && workspace_by_number(_target)) {
free(_target);
free(dup);
return;
@@ -233,18 +228,18 @@ static bool _workspace_by_number(struct sway_container *view, void *data) {
if (view->type != C_WORKSPACE) {
return false;
}
- struct workspace_by_number_data *wbnd = data;
- int a = strspn(view->name, wbnd->cset);
- return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0;
+ char *name = data;
+ char *view_name = view->name;
+ while (isdigit(*name)) {
+ if (*name++ != *view_name++) {
+ return false;
+ }
+ }
+ return !isdigit(*view_name);
}
struct sway_container *workspace_by_number(const char* name) {
- struct workspace_by_number_data wbnd = {0, "1234567890", name};
- wbnd.len = strspn(name, wbnd.cset);
- if (wbnd.len <= 0) {
- return NULL;
- }
- return root_find_workspace(_workspace_by_number, (void *) &wbnd);
+ return root_find_workspace(_workspace_by_number, (void *) name);
}
static bool _workspace_by_name(struct sway_container *view, void *data) {