From 81e55d7f1edad6e21cad84dd807feecab8895bdd Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Mon, 30 Nov 2020 17:04:03 +0100 Subject: [PATCH] #739 remove silly restriction for space labels --- CHANGELOG.md | 1 + src/message.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbdd7bbf..0767f6db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Space/Window commands that utilize the scripting addition should correctly return a non-zero exit code upon failure [#181](https://github.com/koekeishiya/yabai/issues/181) - Undo [#545](https://github.com/koekeishiya/yabai/issues/545) because it created weird issues with focus [#660](https://github.com/koekeishiya/yabai/issues/660) - Allow enabling/disabling *mouse_follows_focus* for specific windows using rules, overriding the global setting [#675](https://github.com/koekeishiya/yabai/issues/675) +- Space labels are now allowed to start with a digit, as long as it is followed by at least one or more non-digit character(s) [#739](https://github.com/koekeishiya/yabai/issues/739) ## [3.3.4] - 2020-11-14 ### Changed diff --git a/src/message.c b/src/message.c index 208692f2..4927814b 100644 --- a/src/message.c +++ b/src/message.c @@ -337,7 +337,17 @@ static bool token_is_float(struct token token, float *value) char buffer[token.length + 1]; memcpy(buffer, token.text, token.length); buffer[token.length] = '\0'; - return sscanf(buffer, "%f", value) == 1; + + char *end = NULL; + float v = strtof(buffer, &end); + + if (!end || *end) { + *value = 0.0f; + return false; + } else { + *value = v; + return true; + } } static char *token_to_string(struct token token, bool temp) @@ -460,14 +470,15 @@ static char *reserved_space_identifiers[] = static bool parse_label(FILE *rsp, char **message, enum label_type type, char **label) { struct token token = get_token(message); + struct token_value value = token_to_value(token, false); - if (!token_is_valid(token)) { + if (value.type == TOKEN_TYPE_INVALID) { *label = NULL; return true; } - if ((token.text[0] >= '0' && token.text[0] <= '9')) { - daemon_fail(rsp, "'%.*s' is not a valid label.\n", token.length, token.text); + if (value.type != TOKEN_TYPE_STRING) { + daemon_fail(rsp, "'%.*s' cannot be used as a label.\n", token.length, token.text); return false; }