summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-05 17:10:55 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-05 17:10:55 +0200
commitb288ba9f1dd29ba34f236e3099f779d5ab130227 (patch)
tree1c4d28ae2700cf85fd3535e67bdcc285d5741eab
parent4f2417ffeedbb687a59a36547e8143724a86bb31 (diff)
patch 8.2.2941: Vim9: using does not handle a list of stringsv8.2.2941
Problem: Vim9: using does not handle a list of strings. Solution: Convert a list to a string and escape each item. (closes #8310)
-rw-r--r--src/testdir/test_vim9_cmd.vim4
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c29
3 files changed, 30 insertions, 5 deletions
diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim
index 87832ce2eb..6b31a62222 100644
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -34,6 +34,10 @@ def Test_edit_wildcards()
CheckDefFailure(['edit `=xxx`'], 'E1001:')
CheckDefFailure(['edit `="foo"'], 'E1083:')
+
+ var files = ['file 1', 'file%2', 'file# 3']
+ args `=files`
+ assert_equal(files, argv())
enddef
def Test_expand_alternate_file()
diff --git a/src/version.c b/src/version.c
index e244d4b957..0f539ca2ee 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 */
/**/
+ 2941,
+/**/
2940,
/**/
2939,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index b23879d3ef..9826678293 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -999,15 +999,34 @@ do_2string(typval_T *tv, int is_2string_any, int tolerant)
case VAR_LIST:
if (tolerant)
{
- char_u *p;
+ char_u *s, *e, *p;
+ garray_T ga;
+ ga_init2(&ga, sizeof(char_u *), 1);
+
+ // Convert to NL separated items, then
+ // escape the items and replace the NL with
+ // a space.
str = typval2string(tv, TRUE);
+ if (str == NULL)
+ return FAIL;
+ s = str;
+ while ((e = vim_strchr(s, '\n')) != NULL)
+ {
+ *e = NUL;
+ p = vim_strsave_fnameescape(s, FALSE);
+ if (p != NULL)
+ {
+ ga_concat(&ga, p);
+ ga_concat(&ga, (char_u *)" ");
+ vim_free(p);
+ }
+ s = e + 1;
+ }
+ vim_free(str);
clear_tv(tv);
tv->v_type = VAR_STRING;
- tv->vval.v_string = str;
- // TODO: escaping
- while ((p = vim_strchr(str, '\n')) != NULL)
- *p = ' ';
+ tv->vval.v_string = ga.ga_data;
return OK;
}
// FALLTHROUGH