diff options
-rw-r--r-- | src/errors.h | 2 | ||||
-rw-r--r-- | src/filepath.c | 8 | ||||
-rw-r--r-- | src/proto/typval.pro | 1 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 48 | ||||
-rw-r--r-- | src/typval.c | 22 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 59 insertions, 24 deletions
diff --git a/src/errors.h b/src/errors.h index b8ec9866b6..30f0dc56e6 100644 --- a/src/errors.h +++ b/src/errors.h @@ -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")); diff --git a/src/filepath.c b/src/filepath.c index 89fafe3134..347612a802 100644 --- a/src/filepath.c +++ b/src/filepath.c @@ -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); diff --git a/src/proto/typval.pro b/src/proto/typval.pro index eafc0e6909..46f893147a 100644 --- a/src/proto/typval.pro +++ b/src/proto/typval.pro @@ -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); diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 927a01fe4f..a0504672d3 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -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() diff --git a/src/typval.c b/src/typval.c index 64112e738c..affd668e92 100644 --- a/src/typval.c +++ b/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; @@ -357,6 +355,22 @@ check_for_string(typval_T *tv) } /* + * 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. * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE! diff --git a/src/version.c b/src/version.c index 5bc5f55350..6b0ec417ec 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2133, +/**/ 2132, /**/ 2131, |