core: fix execution of empty command name

The strings "/" and "/ " are not considered as valid commands any more.
v2.8-utf8proc
Sébastien Helleu 2015-12-31 19:07:14 +01:00
parent 295158d3e1
commit 57b6e320d3
3 changed files with 31 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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);