Patch 8.2.4653
Problem:    "import autoload" does not check the file name.
Solution:   Give an error if the file is not readable. (closes #10049)
Files:      src/filepath.c, src/proto/filepath.pro, src/errors.h,
            src/ex_cmds.c, src/ex_docmd.c, src/spellfile.c,
            src/testdir/test_vim9_import.vim


*** ../vim-8.2.4652/src/filepath.c      2022-03-10 12:23:59.410154437 +0000
--- src/filepath.c      2022-03-31 11:30:25.779649106 +0100
***************
*** 893,924 ****
  }
  
  /*
!  * "filereadable()" function
   */
!     void
! f_filereadable(typval_T *argvars, typval_T *rettv)
  {
      int               fd;
-     char_u    *p;
-     int               n;
- 
-     if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
-       return;
  
  #ifndef O_NONBLOCK
  # define O_NONBLOCK 0
  #endif
!     p = tv_get_string(&argvars[0]);
!     if (*p && !mch_isdir(p) && (fd = mch_open((char *)p,
!                                             O_RDONLY | O_NONBLOCK, 0)) >= 0)
      {
-       n = TRUE;
        close(fd);
      }
!     else
!       n = FALSE;
  
!     rettv->vval.v_number = n;
  }
  
  /*
--- 893,926 ----
  }
  
  /*
!  * Return TRUE if "fname" is a readable file.
   */
!     int
! file_is_readable(char_u *fname)
  {
      int               fd;
  
  #ifndef O_NONBLOCK
  # define O_NONBLOCK 0
  #endif
!     if (*fname && !mch_isdir(fname)
!             && (fd = mch_open((char *)fname, O_RDONLY | O_NONBLOCK, 0)) >= 0)
      {
        close(fd);
+       return TRUE;
      }
!     return FALSE;
! }
  
! /*
!  * "filereadable()" function
!  */
!     void
! f_filereadable(typval_T *argvars, typval_T *rettv)
! {
!     if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
!       return;
!     rettv->vval.v_number = file_is_readable(tv_get_string(&argvars[0]));
  }
  
  /*
***************
*** 1761,1767 ****
  
      if (mch_isdir(fname))
      {
!       semsg(_(e_src_is_directory), fname);
        return;
      }
      if (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL)
--- 1763,1769 ----
  
      if (mch_isdir(fname))
      {
!       semsg(_(e_str_is_directory), fname);
        return;
      }
      if (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL)
*** ../vim-8.2.4652/src/proto/filepath.pro      2021-01-13 19:37:44.439646243 
+0000
--- src/proto/filepath.pro      2022-03-31 11:22:39.671936361 +0100
***************
*** 5,10 ****
--- 5,11 ----
  void f_delete(typval_T *argvars, typval_T *rettv);
  void f_executable(typval_T *argvars, typval_T *rettv);
  void f_exepath(typval_T *argvars, typval_T *rettv);
+ int file_is_readable(char_u *fname);
  void f_filereadable(typval_T *argvars, typval_T *rettv);
  void f_filewritable(typval_T *argvars, typval_T *rettv);
  void f_finddir(typval_T *argvars, typval_T *rettv);
*** ../vim-8.2.4652/src/errors.h        2022-03-21 19:47:27.908641008 +0000
--- src/errors.h        2022-03-31 11:20:33.795992048 +0100
***************
*** 30,37 ****
  #endif
  EXTERN char e_invalid_range[]
        INIT(= N_("E16: Invalid range"));
! #if defined(UNIX) || defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
! EXTERN char e_src_is_directory[]
        INIT(= N_("E17: \"%s\" is a directory"));
  #endif
  #ifdef FEAT_EVAL
--- 30,38 ----
  #endif
  EXTERN char e_invalid_range[]
        INIT(= N_("E16: Invalid range"));
! #if defined(UNIX) || defined(FEAT_SYN_HL) \
!           || defined(FEAT_SPELL) || defined(FEAT_EVAL)
! EXTERN char e_str_is_directory[]
        INIT(= N_("E17: \"%s\" is a directory"));
  #endif
  #ifdef FEAT_EVAL
*** ../vim-8.2.4652/src/ex_cmds.c       2022-03-22 20:42:09.174172862 +0000
--- src/ex_cmds.c       2022-03-31 11:19:10.124021245 +0100
***************
*** 2116,2122 ****
            // with UNIX it is possible to open a directory
            if (mch_isdir(ffname))
            {
!               semsg(_(e_src_is_directory), ffname);
                return FAIL;
            }
  #endif
--- 2116,2122 ----
            // with UNIX it is possible to open a directory
            if (mch_isdir(ffname))
            {
!               semsg(_(e_str_is_directory), ffname);
                return FAIL;
            }
  #endif
*** ../vim-8.2.4652/src/ex_docmd.c      2022-03-27 18:11:01.458525523 +0100
--- src/ex_docmd.c      2022-03-31 11:19:29.740015018 +0100
***************
*** 8386,8392 ****
      // with Unix it is possible to open a directory
      if (mch_isdir(fname))
      {
!       semsg(_(e_src_is_directory), fname);
        return NULL;
      }
  #endif
--- 8386,8392 ----
      // with Unix it is possible to open a directory
      if (mch_isdir(fname))
      {
!       semsg(_(e_str_is_directory), fname);
        return NULL;
      }
  #endif
*** ../vim-8.2.4652/src/spellfile.c     2022-02-25 21:47:44.905532201 +0000
--- src/spellfile.c     2022-03-31 11:20:04.084003199 +0100
***************
*** 5976,5982 ****
        }
        if (mch_isdir(wfname))
        {
!           semsg(_(e_src_is_directory), wfname);
            goto theend;
        }
  
--- 5976,5982 ----
        }
        if (mch_isdir(wfname))
        {
!           semsg(_(e_str_is_directory), wfname);
            goto theend;
        }
  
*** ../vim-8.2.4652/src/testdir/test_vim9_import.vim    2022-03-30 
21:12:16.451923056 +0100
--- src/testdir/test_vim9_import.vim    2022-03-31 11:34:07.679485902 +0100
***************
*** 2508,2520 ****
        vim9script
        import autoload './doesNotExist.vim'
    END
!   v9.CheckScriptSuccess(lines)
  
    lines =<< trim END
        vim9script
        import autoload '/dir/doesNotExist.vim'
    END
!   v9.CheckScriptSuccess(lines)
  
    lines =<< trim END
        vim9script
--- 2508,2526 ----
        vim9script
        import autoload './doesNotExist.vim'
    END
!   v9.CheckScriptFailure(lines, 'E282:', 2)
  
    lines =<< trim END
        vim9script
        import autoload '/dir/doesNotExist.vim'
    END
!   v9.CheckScriptFailure(lines, 'E282:', 2)
! 
!   lines =<< trim END
!       vim9script
!       import autoload '../testdir'
!   END
!   v9.CheckScriptFailure(lines, 'E17:', 2)
  
    lines =<< trim END
        vim9script
*** ../vim-8.2.4652/src/version.c       2022-03-31 10:13:44.130427942 +0100
--- src/version.c       2022-03-31 11:35:45.131411093 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4653,
  /**/

-- 
TALL KNIGHT: When you have found the shrubbery, then you must cut down the
             mightiest tree in the forest ... with a herring.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/20220331103828.6BFED1C1427%40moolenaar.net.

Raspunde prin e-mail lui