mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
core: fix execution of multiple commands separated by newline when there are no spaces
For example typing this on core buffer: /t1 /t2 was not executing the two commands but sent the text to the buffer instead. This is because WeeChat thinks it's a path, and the newline should indicate it's not (like a space before the next slash: "/t1 /t2" is a command, not a path, but "/t1/t2" is considered a path).
This commit is contained in:
@@ -3909,7 +3909,7 @@ string_is_command_char (const char *string)
|
||||
const char *
|
||||
string_input_for_buffer (const char *string)
|
||||
{
|
||||
char *pos_slash, *pos_space;
|
||||
char *pos_slash, *pos_space, *pos_newline;
|
||||
const char *next_char;
|
||||
|
||||
if (!string)
|
||||
@@ -3925,18 +3925,22 @@ string_input_for_buffer (const char *string)
|
||||
|
||||
/*
|
||||
* special case if string starts with '/': to allow to paste a path line
|
||||
* "/path/to/file.txt", we check if next '/' is after a space or not
|
||||
* "/path/to/file.txt", we check if next '/' is after a space/newline
|
||||
* or not
|
||||
*/
|
||||
if (string[0] == '/')
|
||||
{
|
||||
pos_slash = strchr (string + 1, '/');
|
||||
pos_space = strchr (string + 1, ' ');
|
||||
pos_newline = strchr (string + 1, '\n');
|
||||
|
||||
/*
|
||||
* if there are no other '/' or if '/' is after first space,
|
||||
* if there are no other '/' or if '/' is after first space/newline,
|
||||
* then it is a command, and return NULL
|
||||
*/
|
||||
if (!pos_slash || (pos_space && pos_slash > pos_space))
|
||||
if (!pos_slash
|
||||
|| (pos_space && (pos_slash > pos_space))
|
||||
|| (pos_newline && (pos_slash > pos_newline)))
|
||||
return NULL;
|
||||
|
||||
return (string[1] == '/') ? string + 1 : string;
|
||||
|
||||
@@ -2490,6 +2490,7 @@ TEST(CoreString, InputForBuffer)
|
||||
POINTERS_EQUAL(NULL, string_input_for_buffer ("/"));
|
||||
POINTERS_EQUAL(NULL, string_input_for_buffer ("/abc"));
|
||||
|
||||
/* not commands */
|
||||
str = strdup ("");
|
||||
STRCMP_EQUAL(str, string_input_for_buffer (str));
|
||||
free (str);
|
||||
@@ -2511,6 +2512,27 @@ TEST(CoreString, InputForBuffer)
|
||||
str = strdup ("//abc");
|
||||
STRCMP_EQUAL(str + 1, string_input_for_buffer (str));
|
||||
free (str);
|
||||
str = strdup ("/abc/def /ghi");
|
||||
STRCMP_EQUAL(str, string_input_for_buffer (str));
|
||||
free (str);
|
||||
str = strdup ("/abc/def /ghi");
|
||||
STRCMP_EQUAL(str, string_input_for_buffer (str));
|
||||
free (str);
|
||||
|
||||
/* commands */
|
||||
POINTERS_EQUAL(NULL, string_input_for_buffer (NULL));
|
||||
str = strdup ("/");
|
||||
POINTERS_EQUAL(NULL, string_input_for_buffer (str));
|
||||
free (str);
|
||||
str = strdup ("/abc");
|
||||
POINTERS_EQUAL(NULL, string_input_for_buffer (str));
|
||||
free (str);
|
||||
str = strdup ("/abc /def");
|
||||
POINTERS_EQUAL(NULL, string_input_for_buffer (str));
|
||||
free (str);
|
||||
str = strdup ("/abc\n/def");
|
||||
POINTERS_EQUAL(NULL, string_input_for_buffer (str));
|
||||
free (str);
|
||||
|
||||
/* test with custom command chars */
|
||||
config_file_option_set (config_look_command_chars, "öï", 1);
|
||||
|
||||
Reference in New Issue
Block a user