fix(excmd): make :def unknown rather than unimplemented (#23150)

This commit is contained in:
zeertzjq 2023-04-17 17:44:08 +08:00 committed by GitHub
parent a30e61eb4d
commit 75d9c413d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 8 deletions

View File

@ -714,15 +714,9 @@ module.cmds = {
addr_type='ADDR_OTHER',
func='ex_debuggreedy',
},
{
command='def',
flags=bit.bor(EXTRA, BANG, SBOXOK, CMDWIN, LOCK_OK),
addr_type='ADDR_NONE',
func='ex_ni',
},
{
command='defer',
flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM, CMDWIN, LOCK_OK),
flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM, SBOXOK, CMDWIN, LOCK_OK),
addr_type='ADDR_NONE',
func='ex_call',
},

View File

@ -2992,6 +2992,11 @@ char *find_ex_command(exarg_T *eap, int *full)
}
assert(eap->cmdidx >= 0);
if (len == 3 && strncmp("def", eap->cmd, 3) == 0) {
// Make :def an unknown command to avoid confusing behavior. #23149
eap->cmdidx = CMD_SIZE;
}
for (; (int)eap->cmdidx < CMD_SIZE;
eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) {
if (strncmp(cmdnames[(int)eap->cmdidx].cmd_name, eap->cmd,
@ -3146,6 +3151,11 @@ void f_fullcommand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
cmdidx_T excmd_get_cmdidx(const char *cmd, size_t len)
{
if (len == 3 && strncmp("def", cmd, 3) == 0) {
// Make :def an unknown command to avoid confusing behavior. #23149
return CMD_SIZE;
}
cmdidx_T idx;
if (!one_letter_cmd(cmd, &idx)) {

View File

@ -2,6 +2,7 @@ local helpers = require("test.functional.helpers")(after_each)
local command = helpers.command
local eq = helpers.eq
local clear = helpers.clear
local funcs = helpers.funcs
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
@ -26,5 +27,18 @@ describe('Ex cmds', function()
pcall_err(command, ':bdelete 9999999999999999999999999999999999999999'))
assert_alive()
end)
end)
it(':def is an unknown command #23149', function()
eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def'))
eq(1, funcs.exists(':d'))
eq('delete', funcs.fullcommand('d'))
eq(1, funcs.exists(':de'))
eq('delete', funcs.fullcommand('de'))
eq(0, funcs.exists(':def'))
eq('', funcs.fullcommand('def'))
eq(1, funcs.exists(':defe'))
eq('defer', funcs.fullcommand('defe'))
eq(2, funcs.exists(':defer'))
eq('defer', funcs.fullcommand('defer'))
end)
end)