mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Problem: Vim9: checking for a non-empty string is too strict. Solution: Check for any string. (closes #7447)
This commit is contained in:
parent
3ae50c775c
commit
2a9d5d386b
@ -313,3 +313,5 @@ EXTERN char e_for_argument_must_be_sequence_of_lists[]
|
||||
INIT(= N_("E1140: For argument must be a sequence of lists"));
|
||||
EXTERN char e_indexable_type_required[]
|
||||
INIT(= N_("E1141: Indexable type required"));
|
||||
EXTERN char e_non_empty_string_required[]
|
||||
INIT(= N_("E1142: Non-empty string required"));
|
||||
|
@ -876,7 +876,7 @@ f_exepath(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
char_u *p = NULL;
|
||||
|
||||
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
|
||||
if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
|
||||
return;
|
||||
(void)mch_can_exe(tv_get_string(&argvars[0]), &p, TRUE);
|
||||
rettv->v_type = VAR_STRING;
|
||||
@ -942,7 +942,7 @@ findfilendir(
|
||||
|
||||
rettv->vval.v_string = NULL;
|
||||
rettv->v_type = VAR_STRING;
|
||||
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
|
||||
if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
|
||||
return;
|
||||
|
||||
#ifdef FEAT_SEARCHPATH
|
||||
@ -1028,9 +1028,9 @@ f_fnamemodify(typval_T *argvars, typval_T *rettv)
|
||||
return;
|
||||
fname = tv_get_string_chk(&argvars[0]);
|
||||
mods = tv_get_string_buf_chk(&argvars[1], buf);
|
||||
if (fname == NULL || mods == NULL)
|
||||
if (fname == NULL)
|
||||
fname = NULL;
|
||||
else
|
||||
else if (mods != NULL && *mods != NUL)
|
||||
{
|
||||
len = (int)STRLEN(fname);
|
||||
(void)modify_fname(mods, FALSE, &usedlen, &fname, &fbuf, &len);
|
||||
|
@ -10,6 +10,7 @@ varnumber_T tv_get_bool(typval_T *varp);
|
||||
varnumber_T tv_get_bool_chk(typval_T *varp, int *denote);
|
||||
float_T tv_get_float(typval_T *varp);
|
||||
int check_for_string(typval_T *tv);
|
||||
int check_for_nonempty_string(typval_T *tv);
|
||||
char_u *tv_get_string(typval_T *varp);
|
||||
char_u *tv_get_string_buf(typval_T *varp, char_u *buf);
|
||||
char_u *tv_get_string_chk(typval_T *varp);
|
||||
|
@ -186,15 +186,17 @@ def Test_count()
|
||||
enddef
|
||||
|
||||
def Test_executable()
|
||||
assert_false(executable(""))
|
||||
assert_false(executable(test_null_string()))
|
||||
|
||||
CheckDefExecFailure(['echo executable(123)'], 'E928:')
|
||||
CheckDefExecFailure(['echo executable(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo executable(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo executable("")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_exepath()
|
||||
CheckDefExecFailure(['echo exepath(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo exepath(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo exepath("")'], 'E928:')
|
||||
CheckDefExecFailure(['echo exepath("")'], 'E1142:')
|
||||
enddef
|
||||
|
||||
def Test_expand()
|
||||
@ -254,36 +256,42 @@ def Test_map_function_arg()
|
||||
enddef
|
||||
|
||||
def Test_filereadable()
|
||||
assert_false(filereadable(""))
|
||||
assert_false(filereadable(test_null_string()))
|
||||
|
||||
CheckDefExecFailure(['echo filereadable(123)'], 'E928:')
|
||||
CheckDefExecFailure(['echo filereadable(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo filereadable(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo filereadable("")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_filewritable()
|
||||
assert_false(filewritable(""))
|
||||
assert_false(filewritable(test_null_string()))
|
||||
|
||||
CheckDefExecFailure(['echo filewritable(123)'], 'E928:')
|
||||
CheckDefExecFailure(['echo filewritable(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo filewritable(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo filewritable("")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_finddir()
|
||||
CheckDefExecFailure(['echo finddir(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo finddir(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo finddir("")'], 'E928:')
|
||||
CheckDefExecFailure(['echo finddir("")'], 'E1142:')
|
||||
enddef
|
||||
|
||||
def Test_findfile()
|
||||
CheckDefExecFailure(['echo findfile(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo findfile(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo findfile("")'], 'E928:')
|
||||
CheckDefExecFailure(['echo findfile("")'], 'E1142:')
|
||||
enddef
|
||||
|
||||
def Test_fnamemodify()
|
||||
CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")'])
|
||||
CheckDefSuccess(['echo fnamemodify("", ":p")'])
|
||||
CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
|
||||
CheckDefSuccess(['echo fnamemodify("file", "")'])
|
||||
|
||||
CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E928:')
|
||||
CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E928:')
|
||||
CheckDefExecFailure(['echo fnamemodify("", ":p")'], 'E928:')
|
||||
CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo fnamemodify("file", v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo fnamemodify("file", "")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_filter_wrong_dict_key_type()
|
||||
@ -359,27 +367,35 @@ def Test_getloclist_return_type()
|
||||
enddef
|
||||
|
||||
def Test_getfperm()
|
||||
assert_equal('', getfperm(""))
|
||||
assert_equal('', getfperm(test_null_string()))
|
||||
|
||||
CheckDefExecFailure(['echo getfperm(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getfperm(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getfperm("")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_getfsize()
|
||||
assert_equal(-1, getfsize(""))
|
||||
assert_equal(-1, getfsize(test_null_string()))
|
||||
|
||||
CheckDefExecFailure(['echo getfsize(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getfsize(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getfsize("")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_getftime()
|
||||
assert_equal(-1, getftime(""))
|
||||
assert_equal(-1, getftime(test_null_string()))
|
||||
|
||||
CheckDefExecFailure(['echo getftime(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getftime(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getftime("")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_getftype()
|
||||
assert_equal('', getftype(""))
|
||||
assert_equal('', getftype(test_null_string()))
|
||||
|
||||
CheckDefExecFailure(['echo getftype(true)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getftype(v:null)'], 'E928:')
|
||||
CheckDefExecFailure(['echo getftype("")'], 'E928:')
|
||||
enddef
|
||||
|
||||
def Test_getqflist_return_type()
|
||||
|
22
src/typval.c
22
src/typval.c
@ -341,14 +341,12 @@ tv_get_float(typval_T *varp)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Give an error and return FAIL unless "tv" is a non-empty string.
|
||||
* Give an error and return FAIL unless "tv" is a string.
|
||||
*/
|
||||
int
|
||||
check_for_string(typval_T *tv)
|
||||
{
|
||||
if (tv->v_type != VAR_STRING
|
||||
|| tv->vval.v_string == NULL
|
||||
|| *tv->vval.v_string == NUL)
|
||||
if (tv->v_type != VAR_STRING)
|
||||
{
|
||||
emsg(_(e_stringreq));
|
||||
return FAIL;
|
||||
@ -356,6 +354,22 @@ check_for_string(typval_T *tv)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Give an error and return FAIL unless "tv" is a non-empty string.
|
||||
*/
|
||||
int
|
||||
check_for_nonempty_string(typval_T *tv)
|
||||
{
|
||||
if (check_for_string(tv) == FAIL)
|
||||
return FAIL;
|
||||
if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL)
|
||||
{
|
||||
emsg(_(e_non_empty_string_required));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the string value of a variable.
|
||||
* If it is a Number variable, the number is converted into a string.
|
||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2133,
|
||||
/**/
|
||||
2132,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user