aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/executor.c
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2022-04-13 08:04:56 -0600
committerGitHub <noreply@github.com>2022-04-13 08:04:56 -0600
commite463eb81465978b5de77e207af9ee1b416ca0053 (patch)
treeda86f1a31a332690c2c265a24e321e6255b0c1fa /src/nvim/lua/executor.c
parent4dc09f38ee709cadc745ac44a1cc24c4c526ecaf (diff)
downloadrneovim-e463eb81465978b5de77e207af9ee1b416ca0053.tar.gz
rneovim-e463eb81465978b5de77e207af9ee1b416ca0053.tar.bz2
rneovim-e463eb81465978b5de77e207af9ee1b416ca0053.zip
fix(api): correctly pass f-args for nvim_create_user_command (#18098)
Skip runs of whitespace and do not include `\` characters when followed by another `\` or whitespace. This matches the behavior of <f-args> when used with `:command`.
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r--src/nvim/lua/executor.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 21625854fb..81396f1715 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1869,17 +1869,21 @@ void nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap)
} else {
// Commands with more than one possible argument we split
lua_pop(lstate, 1); // Pop the reference of opts.args
- int length = (int)STRLEN(eap->arg);
- int start = 0;
- int end = 0;
+ size_t length = STRLEN(eap->arg);
+ size_t end = 0;
+ size_t len = 0;
int i = 1;
- bool res = true;
- while (res) {
- res = uc_split_args_iter(eap->arg, i, &start, &end, length);
- lua_pushlstring(lstate, (const char *)eap->arg + start, (size_t)(end - start + 1));
- lua_rawseti(lstate, -2, i);
- i++;
+ char *buf = xcalloc(length, sizeof(char));
+ bool done = false;
+ while (!done) {
+ done = uc_split_args_iter(eap->arg, length, &end, buf, &len);
+ if (len > 0) {
+ lua_pushlstring(lstate, buf, len);
+ lua_rawseti(lstate, -2, i);
+ i++;
+ }
}
+ xfree(buf);
}
lua_setfield(lstate, -2, "fargs");