summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-05-05 20:28:11 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-05-05 20:28:11 +0200
commit6d7f10ef2010a7b0c31712e06d7db66c3ab6a2ff (patch)
treee13463a6a6ea846bce3c804f5720ea83af049767 /src
parent25d7192677f8a415cd9ba94229d86aecb9ca5797 (diff)
downloadweechat-6d7f10ef2010a7b0c31712e06d7db66c3ab6a2ff.zip
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).
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-string.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index a6634ba7c..2f6a7b3e8 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -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;