Patch 8.2.2133
Problem:    Vim9: checking for a non-empty string is too strict.
Solution:   Check for any string. (closes #7447)
Files:      src/typval.c, src/proto/typval.pro, src/errors.h, src/filepath.c,
            src/testdir/test_vim9_builtin.vim


*** ../vim-8.2.2132/src/typval.c        2020-12-09 12:41:44.934219841 +0100
--- src/typval.c        2020-12-12 18:33:18.436963618 +0100
***************
*** 341,359 ****
  #endif
  
  /*
!  * Give an error and return FAIL unless "tv" is a non-empty string.
   */
      int
  check_for_string(typval_T *tv)
  {
!     if (tv->v_type != VAR_STRING
!           || tv->vval.v_string == NULL
!           || *tv->vval.v_string == NUL)
      {
        emsg(_(e_stringreq));
        return FAIL;
      }
      return OK;
  }
  
  /*
--- 341,373 ----
  #endif
  
  /*
!  * Give an error and return FAIL unless "tv" is a string.
   */
      int
  check_for_string(typval_T *tv)
  {
!     if (tv->v_type != VAR_STRING)
      {
        emsg(_(e_stringreq));
        return FAIL;
      }
      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;
  }
  
  /*
*** ../vim-8.2.2132/src/proto/typval.pro        2020-12-09 12:41:44.934219841 
+0100
--- src/proto/typval.pro        2020-12-12 18:39:30.587820767 +0100
***************
*** 10,15 ****
--- 10,16 ----
  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);
*** ../vim-8.2.2132/src/errors.h        2020-11-28 18:52:29.999995143 +0100
--- src/errors.h        2020-12-12 18:38:56.359926045 +0100
***************
*** 313,315 ****
--- 313,317 ----
        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"));
*** ../vim-8.2.2132/src/filepath.c      2020-12-09 12:41:44.934219841 +0100
--- src/filepath.c      2020-12-12 18:54:49.412986654 +0100
***************
*** 876,882 ****
  {
      char_u *p = NULL;
  
!     if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
        return;
      (void)mch_can_exe(tv_get_string(&argvars[0]), &p, TRUE);
      rettv->v_type = VAR_STRING;
--- 876,882 ----
  {
      char_u *p = NULL;
  
!     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,948 ****
  
      rettv->vval.v_string = NULL;
      rettv->v_type = VAR_STRING;
!     if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
        return;
  
  #ifdef FEAT_SEARCHPATH
--- 942,948 ----
  
      rettv->vval.v_string = NULL;
      rettv->v_type = VAR_STRING;
!     if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
        return;
  
  #ifdef FEAT_SEARCHPATH
***************
*** 1028,1036 ****
        return;
      fname = tv_get_string_chk(&argvars[0]);
      mods = tv_get_string_buf_chk(&argvars[1], buf);
!     if (fname == NULL || mods == NULL)
        fname = NULL;
!     else
      {
        len = (int)STRLEN(fname);
        (void)modify_fname(mods, FALSE, &usedlen, &fname, &fbuf, &len);
--- 1028,1036 ----
        return;
      fname = tv_get_string_chk(&argvars[0]);
      mods = tv_get_string_buf_chk(&argvars[1], buf);
!     if (fname == NULL)
        fname = NULL;
!     else if (mods != NULL && *mods != NUL)
      {
        len = (int)STRLEN(fname);
        (void)modify_fname(mods, FALSE, &usedlen, &fname, &fbuf, &len);
*** ../vim-8.2.2132/src/testdir/test_vim9_builtin.vim   2020-12-09 
12:41:44.934219841 +0100
--- src/testdir/test_vim9_builtin.vim   2020-12-12 18:57:41.924453597 +0100
***************
*** 186,200 ****
  enddef
  
  def Test_executable()
    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:')
  enddef
  
  def Test_expand()
--- 186,202 ----
  enddef
  
  def Test_executable()
+   assert_false(executable(""))
+   assert_false(executable(test_null_string()))
+ 
+   CheckDefExecFailure(['echo executable(123)'], 'E928:')
    CheckDefExecFailure(['echo executable(true)'], 'E928:')
  enddef
  
  def Test_exepath()
    CheckDefExecFailure(['echo exepath(true)'], 'E928:')
    CheckDefExecFailure(['echo exepath(v:null)'], 'E928:')
!   CheckDefExecFailure(['echo exepath("")'], 'E1142:')
  enddef
  
  def Test_expand()
***************
*** 254,289 ****
  enddef
  
  def Test_filereadable()
    CheckDefExecFailure(['echo filereadable(true)'], 'E928:')
-   CheckDefExecFailure(['echo filereadable(v:null)'], 'E928:')
-   CheckDefExecFailure(['echo filereadable("")'], 'E928:')
  enddef
  
  def Test_filewritable()
    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:')
  enddef
  
  def Test_findfile()
    CheckDefExecFailure(['echo findfile(true)'], 'E928:')
    CheckDefExecFailure(['echo findfile(v:null)'], 'E928:')
!   CheckDefExecFailure(['echo findfile("")'], 'E928:')
  enddef
  
  def Test_fnamemodify()
    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()
--- 256,297 ----
  enddef
  
  def Test_filereadable()
+   assert_false(filereadable(""))
+   assert_false(filereadable(test_null_string()))
+ 
+   CheckDefExecFailure(['echo filereadable(123)'], 'E928:')
    CheckDefExecFailure(['echo filereadable(true)'], 'E928:')
  enddef
  
  def Test_filewritable()
+   assert_false(filewritable(""))
+   assert_false(filewritable(test_null_string()))
+ 
+   CheckDefExecFailure(['echo filewritable(123)'], 'E928:')
    CheckDefExecFailure(['echo filewritable(true)'], 'E928:')
  enddef
  
  def Test_finddir()
    CheckDefExecFailure(['echo finddir(true)'], 'E928:')
    CheckDefExecFailure(['echo finddir(v:null)'], 'E928:')
!   CheckDefExecFailure(['echo finddir("")'], 'E1142:')
  enddef
  
  def Test_findfile()
    CheckDefExecFailure(['echo findfile(true)'], 'E928:')
    CheckDefExecFailure(['echo findfile(v:null)'], '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("file", true)'], 'E928:')
  enddef
  
  def Test_filter_wrong_dict_key_type()
***************
*** 359,385 ****
  enddef
  
  def Test_getfperm()
    CheckDefExecFailure(['echo getfperm(true)'], 'E928:')
    CheckDefExecFailure(['echo getfperm(v:null)'], 'E928:')
-   CheckDefExecFailure(['echo getfperm("")'], 'E928:')
  enddef
  
  def Test_getfsize()
    CheckDefExecFailure(['echo getfsize(true)'], 'E928:')
    CheckDefExecFailure(['echo getfsize(v:null)'], 'E928:')
-   CheckDefExecFailure(['echo getfsize("")'], 'E928:')
  enddef
  
  def Test_getftime()
    CheckDefExecFailure(['echo getftime(true)'], 'E928:')
    CheckDefExecFailure(['echo getftime(v:null)'], 'E928:')
-   CheckDefExecFailure(['echo getftime("")'], 'E928:')
  enddef
  
  def Test_getftype()
    CheckDefExecFailure(['echo getftype(true)'], 'E928:')
    CheckDefExecFailure(['echo getftype(v:null)'], 'E928:')
-   CheckDefExecFailure(['echo getftype("")'], 'E928:')
  enddef
  
  def Test_getqflist_return_type()
--- 367,401 ----
  enddef
  
  def Test_getfperm()
+   assert_equal('', getfperm(""))
+   assert_equal('', getfperm(test_null_string()))
+ 
    CheckDefExecFailure(['echo getfperm(true)'], 'E928:')
    CheckDefExecFailure(['echo getfperm(v:null)'], '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:')
  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:')
  enddef
  
  def Test_getftype()
+   assert_equal('', getftype(""))
+   assert_equal('', getftype(test_null_string()))
+ 
    CheckDefExecFailure(['echo getftype(true)'], 'E928:')
    CheckDefExecFailure(['echo getftype(v:null)'], 'E928:')
  enddef
  
  def Test_getqflist_return_type()
*** ../vim-8.2.2132/src/version.c       2020-12-12 18:17:46.463804077 +0100
--- src/version.c       2020-12-12 18:34:21.716768724 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2133,
  /**/

-- 
A disclaimer for the disclaimer:
"and before I get a huge amount of complaints , I have no control over the
disclaimer at the end of this mail :-)" (Timothy Aldrich)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202012121802.0BCI2ghf2853311%40masaka.moolenaar.net.

Raspunde prin e-mail lui