summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-31 11:37:57 +0100
committerBram Moolenaar <Bram@vim.org>2022-03-31 11:37:57 +0100
commit4dea2d92e4c308b064ed1dd7b2ba7527a0d6b0a0 (patch)
treea7be19a7aa8b4a9c4e48084639ad51db96f36db6 /src
parentd1d2684c8006105444d249e846576c23d79ad4ee (diff)
downloadvim-git-4dea2d92e4c308b064ed1dd7b2ba7527a0d6b0a0.tar.gz
patch 8.2.4653: "import autoload" does not check the file namev8.2.4653
Problem: "import autoload" does not check the file name. Solution: Give an error if the file is not readable. (closes #10049)
Diffstat (limited to 'src')
-rw-r--r--src/errors.h5
-rw-r--r--src/ex_cmds.c2
-rw-r--r--src/ex_docmd.c2
-rw-r--r--src/filepath.c34
-rw-r--r--src/proto/filepath.pro1
-rw-r--r--src/spellfile.c2
-rw-r--r--src/testdir/test_vim9_import.vim10
-rw-r--r--src/version.c2
8 files changed, 35 insertions, 23 deletions
diff --git a/src/errors.h b/src/errors.h
index 949a53279..951acabb2 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -30,8 +30,9 @@ EXTERN char e_invalid_expression_str[]
#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[]
+#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
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index be3584535..25f06e623 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2116,7 +2116,7 @@ check_overwrite(
// with UNIX it is possible to open a directory
if (mch_isdir(ffname))
{
- semsg(_(e_src_is_directory), ffname);
+ semsg(_(e_str_is_directory), ffname);
return FAIL;
}
#endif
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index c5e96bde5..c12f151c3 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -8386,7 +8386,7 @@ open_exfile(
// with Unix it is possible to open a directory
if (mch_isdir(fname))
{
- semsg(_(e_src_is_directory), fname);
+ semsg(_(e_str_is_directory), fname);
return NULL;
}
#endif
diff --git a/src/filepath.c b/src/filepath.c
index f0da60f45..851091e57 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -893,32 +893,34 @@ f_exepath(typval_T *argvars, typval_T *rettv)
}
/*
- * "filereadable()" function
+ * Return TRUE if "fname" is a readable file.
*/
- void
-f_filereadable(typval_T *argvars, typval_T *rettv)
+ int
+file_is_readable(char_u *fname)
{
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)
+ if (*fname && !mch_isdir(fname)
+ && (fd = mch_open((char *)fname, O_RDONLY | O_NONBLOCK, 0)) >= 0)
{
- n = TRUE;
close(fd);
+ return TRUE;
}
- else
- n = FALSE;
+ return FALSE;
+}
- rettv->vval.v_number = n;
+/*
+ * "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,7 +1763,7 @@ read_file_or_blob(typval_T *argvars, typval_T *rettv, int always_blob)
if (mch_isdir(fname))
{
- semsg(_(e_src_is_directory), fname);
+ semsg(_(e_str_is_directory), fname);
return;
}
if (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL)
diff --git a/src/proto/filepath.pro b/src/proto/filepath.pro
index 62612117d..bf3d5163d 100644
--- a/src/proto/filepath.pro
+++ b/src/proto/filepath.pro
@@ -5,6 +5,7 @@ void f_chdir(typval_T *argvars, typval_T *rettv);
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);
diff --git a/src/spellfile.c b/src/spellfile.c
index ad0d00021..aaacb2e44 100644
--- a/src/spellfile.c
+++ b/src/spellfile.c
@@ -5976,7 +5976,7 @@ mkspell(
}
if (mch_isdir(wfname))
{
- semsg(_(e_src_is_directory), wfname);
+ semsg(_(e_str_is_directory), wfname);
goto theend;
}
diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim
index b1e96c5ea..c6a820654 100644
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -2508,13 +2508,19 @@ def Test_import_autoload_fails()
vim9script
import autoload './doesNotExist.vim'
END
- v9.CheckScriptSuccess(lines)
+ v9.CheckScriptFailure(lines, 'E282:', 2)
lines =<< trim END
vim9script
import autoload '/dir/doesNotExist.vim'
END
- v9.CheckScriptSuccess(lines)
+ v9.CheckScriptFailure(lines, 'E282:', 2)
+
+ lines =<< trim END
+ vim9script
+ import autoload '../testdir'
+ END
+ v9.CheckScriptFailure(lines, 'E17:', 2)
lines =<< trim END
vim9script
diff --git a/src/version.c b/src/version.c
index 843affd3e..3db4108f3 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 */
/**/
+ 4653,
+/**/
4652,
/**/
4651,