Skip to content
Permalink
Browse files

core: fix execution of empty command name

The strings "/" and "/ " are not considered as valid commands any more.
  • Loading branch information...
flashcode committed Dec 31, 2015
1 parent 295158d commit 57b6e320d3c9d2d9473090eb3881de206c81e52c
Showing with 31 additions and 3 deletions.
  1. +2 −0 ChangeLog.asciidoc
  2. +14 −2 src/core/wee-string.c
  3. +15 −1 tests/unit/core/test-string.cpp
@@ -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
@@ -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)
@@ -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);

0 comments on commit 57b6e32

Please sign in to comment.
You can’t perform that action at this time.