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`.
This commit is contained in:
Gregory Anders
2022-04-13 08:04:56 -06:00
committed by GitHub
parent 4dc09f38ee
commit e463eb8146
3 changed files with 86 additions and 34 deletions

View File

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