Patch 8.2.2941

5 views
Skip to first unread message

Bram Moolenaar

unread,
Jun 5, 2021, 11:11:29 AM6/5/21
to vim...@googlegroups.com

Patch 8.2.2941
Problem: Vim9: using `=expr` does not handle a list of strings.
Solution: Convert a list to a string and escape each item. (closes #8310)
Files: src/vim9execute.c, src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.2940/src/vim9execute.c 2021-06-04 21:00:27.958234335 +0200
--- src/vim9execute.c 2021-06-05 17:08:09.606394715 +0200
***************
*** 999,1013 ****
case VAR_LIST:
if (tolerant)
{
! char_u *p;

str = typval2string(tv, TRUE);
clear_tv(tv);
tv->v_type = VAR_STRING;
! tv->vval.v_string = str;
! // TODO: escaping
! while ((p = vim_strchr(str, '\n')) != NULL)
! *p = ' ';
return OK;
}
// FALLTHROUGH
--- 999,1032 ----
case VAR_LIST:
if (tolerant)
{
! 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 = ga.ga_data;
return OK;
}
// FALLTHROUGH
*** ../vim-8.2.2940/src/testdir/test_vim9_cmd.vim 2021-05-09 23:19:17.093003109 +0200
--- src/testdir/test_vim9_cmd.vim 2021-06-05 17:01:13.367479644 +0200
***************
*** 34,39 ****
--- 34,43 ----

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()
*** ../vim-8.2.2940/src/version.c 2021-06-05 16:25:29.189758206 +0200
--- src/version.c 2021-06-05 17:08:48.814295986 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2941,
/**/

--
[The rest of the ARMY stand around looking at a loss.]
INSPECTOR END OF FILM: (picks up megaphone) All right! Clear off! Go on!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages