1
0
forked from aniani/vim

patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit

Problem:    Vim9: accidentally using "x" causes Vim to exit.
Solution:   Disallow using ":x" or "xit" in Vim9 script. (closes #6399)
This commit is contained in:
Bram Moolenaar
2020-07-28 20:07:27 +02:00
parent 0aac67a431
commit ae616494d7
8 changed files with 78 additions and 26 deletions

View File

@@ -3176,6 +3176,9 @@ ex_append(exarg_T *eap)
int vcol;
int empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
if (not_in_vim9(eap) == FAIL)
return;
// the ! flag toggles autoindent
if (eap->forceit)
curbuf->b_p_ai = !curbuf->b_p_ai;
@@ -3317,6 +3320,9 @@ ex_change(exarg_T *eap)
{
linenr_T lnum;
if (not_in_vim9(eap) == FAIL)
return;
if (eap->line2 >= eap->line1
&& u_save(eap->line1 - 1, eap->line2 + 1) == FAIL)
return;

View File

@@ -5686,6 +5686,8 @@ ex_stop(exarg_T *eap)
static void
ex_exit(exarg_T *eap)
{
if (not_in_vim9(eap) == FAIL)
return;
#ifdef FEAT_CMDWIN
if (cmdwin_type != 0)
{

View File

@@ -1,6 +1,7 @@
/* vim9script.c */
int in_vim9script(void);
void ex_vim9script(exarg_T *eap);
int not_in_vim9(exarg_T *eap);
void ex_export(exarg_T *eap);
void free_imports(int sid);
void ex_import(exarg_T *eap);

View File

@@ -1515,6 +1515,21 @@ def Test_fixed_size_list()
assert_equal([2, 99, 3, 4, 5], l)
enddef
def Test_no_insert_xit()
call CheckDefExecFailure(['x = 1'], 'E1100:')
call CheckDefExecFailure(['a = 1'], 'E1100:')
call CheckDefExecFailure(['i = 1'], 'E1100:')
call CheckDefExecFailure(['c = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'a = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'a'], 'E1100:')
CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'i'], 'E1100:')
CheckScriptFailure(['vim9script', 'c = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'c'], 'E1100:')
enddef
def IfElse(what: number): string
let res = ''
if what == 1

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1308,
/**/
1307,
/**/

View File

@@ -7409,6 +7409,13 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
// TODO: other commands with an expression argument
case CMD_append:
case CMD_change:
case CMD_insert:
case CMD_xit:
not_in_vim9(&ea);
goto erret;
case CMD_SIZE:
semsg(_("E476: Invalid command: %s"), ea.cmd);
goto erret;

View File

@@ -58,13 +58,30 @@ ex_vim9script(exarg_T *eap)
}
}
/*
* When in Vim9 script give an error and return FAIL.
*/
int
not_in_vim9(exarg_T *eap)
{
switch (eap->cmdidx)
{
case CMD_insert:
case CMD_append:
case CMD_change:
case CMD_xit:
semsg(_("E1100: Missing :let: %s"), eap->cmd);
return FAIL;
default: break;
}
return OK;
}
/*
* ":export let Name: type"
* ":export const Name: type"
* ":export def Name(..."
* ":export class Name ..."
*
* ":export {Name, ...}"
*/
void
ex_export(exarg_T *eap)