]> granicus.if.org Git - vim/commitdiff
patch 8.2.2941: Vim9: using does not handle a list of strings v8.2.2941
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Jun 2021 15:10:55 +0000 (17:10 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Jun 2021 15:10:55 +0000 (17:10 +0200)
Problem:    Vim9: using  does not handle a list of strings.
Solution:   Convert a list to a string and escape each item. (closes #8310)

src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9execute.c

index 87832ce2eb01a88dfd44414fa1f248a8f2646563..6b31a62222bfc314e4597825fd334a0e8cdf7377 100644 (file)
@@ -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()
index e244d4b957be917aca8db56a163fe0e43163a38d..0f539ca2ee82ee581c8011c009d10864c99e956e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2941,
 /**/
     2940,
 /**/
index b23879d3ef2d924654f140f6915a61d7d9803e4c..9826678293fed7774f462ef1e707f0eb05f7f898 100644 (file)
@@ -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