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

@@ -180,6 +180,28 @@ describe('nvim_add_user_command', function()
feed('<C-U>Test b<Tab>')
eq('Test bbb', funcs.getcmdline())
end)
it('does not allow invalid command names', function()
matches("'name' must begin with an uppercase letter", pcall_err(exec_lua, [[
vim.api.nvim_add_user_command('test', 'echo "hi"', {})
]]))
matches('Invalid command name', pcall_err(exec_lua, [[
vim.api.nvim_add_user_command('t@', 'echo "hi"', {})
]]))
matches('Invalid command name', pcall_err(exec_lua, [[
vim.api.nvim_add_user_command('T@st', 'echo "hi"', {})
]]))
matches('Invalid command name', pcall_err(exec_lua, [[
vim.api.nvim_add_user_command('Test!', 'echo "hi"', {})
]]))
matches('Invalid command name', pcall_err(exec_lua, [[
vim.api.nvim_add_user_command('💩', 'echo "hi"', {})
]]))
end)
end)
describe('nvim_del_user_command', function()