diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index b5d0b5def..644a83b1c 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -21,6 +21,8 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] [[1.4_features]] === New features +* core: fix execution of empty command name ("/" and "/ " are not valid + commands) * core: add a parent name in options, display inherited values if null in /set output, add option weechat.color.chat_value_null (issue #629) * core: add tag "term_warning" in warnings about wrong $TERM on startup diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 9ae23d7f3..f973f5800 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -2825,6 +2825,14 @@ string_input_for_buffer (const char *string) if (!string) return NULL; + /* a single "/" is not a command */ + if (strcmp (string, "/") == 0) + return string; + + /* "/ " is not a command */ + if (strncmp (string, "/ ", 2) == 0) + return string; + /* special case for C comments pasted in input line */ if (strncmp (string, "/*", 2) == 0) return string; @@ -2854,9 +2862,13 @@ string_input_for_buffer (const char *string) next_char = utf8_next_char (string); - /* there's no next char, then it's a command */ + /* there's no next char, then it's a not command */ if (!next_char || !next_char[0]) - return NULL; + return string; + + /* next char is a space, then it's not a command */ + if (next_char[0] == ' ') + return string; /* check if first char is doubled: if yes, then it's not a command */ if (utf8_charcmp (string, next_char) == 0) diff --git a/tests/unit/core/test-string.cpp b/tests/unit/core/test-string.cpp index cf1a6c464..63fd7f095 100644 --- a/tests/unit/core/test-string.cpp +++ b/tests/unit/core/test-string.cpp @@ -1214,11 +1214,25 @@ TEST(String, Input) /* string_input_for_buffer */ POINTERS_EQUAL(NULL, string_input_for_buffer (NULL)); - POINTERS_EQUAL(NULL, string_input_for_buffer ("/")); POINTERS_EQUAL(NULL, string_input_for_buffer ("/abc")); str = strdup (""); STRCMP_EQUAL(str, string_input_for_buffer (str)); free (str); + str = strdup ("/"); + STRCMP_EQUAL(str, string_input_for_buffer (str)); + free (str); + str = strdup ("/ "); + STRCMP_EQUAL(str, string_input_for_buffer (str)); + free (str); + str = strdup ("/ abc"); + STRCMP_EQUAL(str, string_input_for_buffer (str)); + free (str); + str = strdup ("/ /"); + STRCMP_EQUAL(str, string_input_for_buffer (str)); + free (str); + str = strdup ("/*"); + STRCMP_EQUAL(str, string_input_for_buffer (str)); + free (str); str = strdup ("abc"); STRCMP_EQUAL(str, string_input_for_buffer (str)); free (str);