]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1178: Vim9: filter function recognized as command modifier v8.2.1178
authorBram Moolenaar <Bram@vim.org>
Sat, 11 Jul 2020 11:40:45 +0000 (13:40 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 11 Jul 2020 11:40:45 +0000 (13:40 +0200)
Problem:    Vim9: filter function recognized as command modifier, leading to a
            crash.
Solution:   Clear cmdmod after freeing items.  Do not recognize a command
            modifier followed by non-white space. (closes #6434)

src/ex_docmd.c
src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9compile.c

index 0573897b7c7f03f0d63defd770b97b8bec9641ca..692192bb1886ef4007ef3a2b2b8e68483c7f2400 100644 (file)
@@ -2750,6 +2750,10 @@ parse_command_modifiers(exarg_T *eap, char **errormsg, int skip_only)
                                if (*p == NUL || ends_excmd(*p))
                                    break;
                            }
+                           // Avoid that "filter(arg)" is recognized.
+                           if (in_vim9script() && !VIM_ISWHITE(*p))
+                               break;
+
                            if (skip_only)
                                p = skip_vimgrep_pat(p, NULL, NULL);
                            else
@@ -2904,7 +2908,7 @@ parse_command_modifiers(exarg_T *eap, char **errormsg, int skip_only)
 }
 
 /*
- * Unod and free contents of "cmdmod".
+ * Undo and free contents of "cmdmod".
  */
     void
 undo_cmdmod(exarg_T *eap, int save_msg_scroll)
index 801404d9c6f81bf1333c9aa7eec6f94da53c2ac2..676e97ceb1a4a08deb2a361c747e8ba0faad9045 100644 (file)
@@ -265,6 +265,12 @@ def Test_bar_after_command()
   endif
 enddef
 
+def Test_filter_is_not_modifier()
+  let tags = [{'a': 1, 'b': 2}, {'x': 3, 'y': 4}]
+  filter(tags, { _, v -> has_key(v, 'x') ? 1 : 0 })
+  assert_equal([#{x: 3, y: 4}], tags)
+enddef
+
 def Test_eval_command()
   let from = 3
   let to = 5
index 4ffa17ffc040c3d6be33f331a90649dca011dfe3..c01d1059d6f488be87b507ac6ff162e0ce628fd0 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1178,
 /**/
     1177,
 /**/
index e7f90e1c7fe88d29acf7de9a805adb0f8559465a..8905ee3742314250c4b5d7147c7902a4be15a2e0 100644 (file)
@@ -6963,6 +6963,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
        }
        // TODO: use modifiers in the command
        undo_cmdmod(&ea, save_msg_scroll);
+       CLEAR_FIELD(cmdmod);
 
        // Skip ":call" to get to the function name.
        if (checkforcmd(&ea.cmd, "call", 3))