summaryrefslogtreecommitdiff
path: root/src/vim9script.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-07-18 18:21:38 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-18 18:21:38 +0200
commit4db572eeb2b42819268e934e76c67163316d873f (patch)
tree7c7b632b8808211dcaecb968090f31aac4e2b13a /src/vim9script.c
parentad2d4969e1616d3a0354c181e3a09271d5433b3d (diff)
downloadvim-git-4db572eeb2b42819268e934e76c67163316d873f.tar.gz
patch 8.2.3178: Vim9: the file name of an :import cannot be an expressionv8.2.3178
Problem: Vim9: the file name of an :import cannot be an expression. Solution: Accept an expression that results in a string. Do not support :import in a function.
Diffstat (limited to 'src/vim9script.c')
-rw-r--r--src/vim9script.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/vim9script.c b/src/vim9script.c
index d40e334ae..85d601c7a 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -412,6 +412,7 @@ handle_import(
garray_T names;
garray_T as_names;
+ tv.v_type = VAR_UNKNOWN;
ga_init2(&names, sizeof(char_u *), 10);
ga_init2(&as_names, sizeof(char_u *), 10);
if (*arg == '{')
@@ -496,14 +497,14 @@ handle_import(
goto erret;
}
+ // The name of the file can be an expression, which must evaluate to a
+ // string.
arg = skipwhite_and_linebreak(arg + 4, evalarg);
- tv.v_type = VAR_UNKNOWN;
- // TODO: should we accept any expression?
- if (*arg == '\'')
- ret = eval_lit_string(&arg, &tv, TRUE);
- else if (*arg == '"')
- ret = eval_string(&arg, &tv, TRUE);
- if (ret == FAIL || tv.vval.v_string == NULL || *tv.vval.v_string == NUL)
+ ret = eval0(arg, &tv, NULL, evalarg);
+ if (ret == FAIL)
+ goto erret;
+ if (tv.v_type != VAR_STRING
+ || tv.vval.v_string == NULL || *tv.vval.v_string == NUL)
{
emsg(_(e_invalid_string_after_from));
goto erret;
@@ -524,10 +525,7 @@ handle_import(
len = STRLEN(si->sn_name) - STRLEN(tail) + STRLEN(tv.vval.v_string) + 2;
from_name = alloc((int)len);
if (from_name == NULL)
- {
- clear_tv(&tv);
goto erret;
- }
vim_strncpy(from_name, si->sn_name, tail - si->sn_name);
add_pathsep(from_name);
STRCAT(from_name, tv.vval.v_string);
@@ -550,7 +548,6 @@ handle_import(
from_name = alloc((int)len);
if (from_name == NULL)
{
- clear_tv(&tv);
goto erret;
}
vim_snprintf((char *)from_name, len, "import/%s", tv.vval.v_string);
@@ -561,10 +558,8 @@ handle_import(
if (res == FAIL || sid <= 0)
{
semsg(_(e_could_not_import_str), tv.vval.v_string);
- clear_tv(&tv);
goto erret;
}
- clear_tv(&tv);
if (*arg_start == '*')
{
@@ -669,6 +664,7 @@ handle_import(
}
}
erret:
+ clear_tv(&tv);
ga_clear_strings(&names);
ga_clear_strings(&as_names);
return cmd_end;