]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1607: :apple command detected as :append v9.1.1607
authorHirohito Higashi <h.east.727@gmail.com>
Fri, 8 Aug 2025 11:25:27 +0000 (13:25 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 8 Aug 2025 11:25:27 +0000 (13:25 +0200)
Problem:  :apple command detected as :append (dai475694450)
Solution: Disallow to define a custom command with lower-case letter,
          correctly detect :insert/:change/:append ex commands
          (Hirohito Higashi).

fixes: #17893
closes: #17930

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vimscript.vim
src/userfunc.c
src/version.c

index af78d1c93d8d6311e1f3baa8c7876f4d2b3f3171..e1b0425ee7105f887f7b1763e76efee4a85adf75 100644 (file)
@@ -6888,6 +6888,52 @@ func Test_script_lines()
     catch
        call assert_exception('Vim(function):E1145: Missing heredoc end marker: .')
     endtry
+
+    " More test for :append, :change, :insert
+    let cmds = ["append", "change", "insert"]
+    let suffixes = ["", "!", "|", "|xyz", " "]
+
+    for c in cmds
+      " Single character (with some accepted trailing characters)
+      for s in suffixes
+        let cmd = c[:0] .. s
+        let line = ["func LinesCheck()", cmd, "", "endfunc", "call LinesCheck()"]
+        call writefile(line, 'Xfunc', 'D')
+        call assert_fails('source Xfunc', 'E1145: Missing heredoc end marker: .', $'"{cmd}"')
+      endfor
+
+      " Unnecessary arguments
+      let cmd = c[:2] .. " end"
+      let line[1] = cmd
+      call writefile(line, 'Xfunc', 'D')
+      call assert_fails('source Xfunc', 'E488: Trailing characters: end:', $'"{cmd}"')
+
+      " Extra characters at the end (i.e., other commands)
+      let cmd = c .. "x"
+      let line[1] = cmd
+      call writefile(line, 'Xfunc', 'D')
+      call assert_fails('source Xfunc', 'E492: Not an editor command:', $'"{cmd}"')
+    endfor
+
+    let line =<< trim END
+    func AppendCheck()
+      apple
+    endfunc
+    call AppendCheck()
+    END
+    call writefile(line, 'Xfunc', 'D')
+    call assert_fails('source Xfunc', 'E492: Not an editor command:   apple')
+
+    let line =<< trim END
+    func AppendCheck()
+      command! apple :echo "hello apple"
+      apple
+    endfunc
+    call AppendCheck()
+    END
+    call writefile(line, 'Xfunc', 'D')
+    call assert_fails('source Xfunc', 'E183: User defined commands must start with an uppercase letter')
+
 endfunc
 
 "-------------------------------------------------------------------------------
index dbd6a4ef151c598de5bd8da5e2a10b3d6d950934..a4d01524ab493de0be6274a984d24ee9a7fb4c1a 100644 (file)
@@ -1282,21 +1282,15 @@ get_function_body(
            }
 
            // Check for ":append", ":change", ":insert".  Not for :def.
-           p = skip_range(p, FALSE, NULL);
+           char_u *tp = p = skip_range(p, FALSE, NULL);
            if (!vim9_function
-               && ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
-                   || (p[0] == 'c'
-                       && (!ASCII_ISALPHA(p[1]) || (p[1] == 'h'
-                               && (!ASCII_ISALPHA(p[2]) || (p[2] == 'a'
-                                       && (STRNCMP(&p[3], "nge", 3) != 0
-                                           || !ASCII_ISALPHA(p[6])))))))
-                   || (p[0] == 'i'
-                       && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
-                               && (!ASCII_ISALPHA(p[2])
-                                   || (p[2] == 's'
-                                       && (!ASCII_ISALPHA(p[3])
-                                               || p[3] == 'e'))))))))
+               && (checkforcmd(&p, "append", 1)
+                   || checkforcmd(&p, "change", 1)
+                   || checkforcmd(&p, "insert", 1))
+                   && (*p == '!' || *p == '|' || IS_WHITE_NL_OR_NUL(*p)))
                skip_until = vim_strnsave((char_u *)".", 1);
+           else
+               p = tp;
 
            // Check for ":python <<EOF", ":tcl <<EOF", etc.
            arg = skipwhite(skiptowhite(p));
index d07747c958b1cabf61e3013187ae3c14b3f7e17f..9ba90af671be070ed3fab0ad1cd54c82d0b8b49b 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1607,
 /**/
     1606,
 /**/