fix(api): validate command names in nvim_add_user_command (#17406)

This uses the same validation used when defining commands with
`:command`.
This commit is contained in:
Gregory Anders
2022-02-15 13:08:40 -07:00
committed by GitHub
parent 3449405f38
commit 238b944e58
3 changed files with 50 additions and 10 deletions

View File

@@ -1384,6 +1384,11 @@ void add_user_command(String name, Object command, Dict(user_command) *opts, int
LuaRef luaref = LUA_NOREF;
LuaRef compl_luaref = LUA_NOREF;
if (!uc_validate_name(name.data)) {
api_set_error(err, kErrorTypeValidation, "Invalid command name");
goto err;
}
if (mb_islower(name.data[0])) {
api_set_error(err, kErrorTypeValidation, "'name' must begin with an uppercase letter");
goto err;