Skip to content

Commit efd83d4

Browse files
h-eastchrisbra
authored andcommitted
patch 9.1.1607: :apple command detected as :append
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>
1 parent eb2aebe commit efd83d4

3 files changed

Lines changed: 55 additions & 13 deletions

File tree

src/testdir/test_vimscript.vim

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6888,6 +6888,52 @@ func Test_script_lines()
68886888
catch
68896889
call assert_exception('Vim(function):E1145: Missing heredoc end marker: .')
68906890
endtry
6891+
6892+
" More test for :append, :change, :insert
6893+
let cmds = ["append", "change", "insert"]
6894+
let suffixes = ["", "!", "|", "|xyz", " "]
6895+
6896+
for c in cmds
6897+
" Single character (with some accepted trailing characters)
6898+
for s in suffixes
6899+
let cmd = c[:0] .. s
6900+
let line = ["func LinesCheck()", cmd, "", "endfunc", "call LinesCheck()"]
6901+
call writefile(line, 'Xfunc', 'D')
6902+
call assert_fails('source Xfunc', 'E1145: Missing heredoc end marker: .', $'"{cmd}"')
6903+
endfor
6904+
6905+
" Unnecessary arguments
6906+
let cmd = c[:2] .. " end"
6907+
let line[1] = cmd
6908+
call writefile(line, 'Xfunc', 'D')
6909+
call assert_fails('source Xfunc', 'E488: Trailing characters: end:', $'"{cmd}"')
6910+
6911+
" Extra characters at the end (i.e., other commands)
6912+
let cmd = c .. "x"
6913+
let line[1] = cmd
6914+
call writefile(line, 'Xfunc', 'D')
6915+
call assert_fails('source Xfunc', 'E492: Not an editor command:', $'"{cmd}"')
6916+
endfor
6917+
6918+
let line =<< trim END
6919+
func AppendCheck()
6920+
apple
6921+
endfunc
6922+
call AppendCheck()
6923+
END
6924+
call writefile(line, 'Xfunc', 'D')
6925+
call assert_fails('source Xfunc', 'E492: Not an editor command: apple')
6926+
6927+
let line =<< trim END
6928+
func AppendCheck()
6929+
command! apple :echo "hello apple"
6930+
apple
6931+
endfunc
6932+
call AppendCheck()
6933+
END
6934+
call writefile(line, 'Xfunc', 'D')
6935+
call assert_fails('source Xfunc', 'E183: User defined commands must start with an uppercase letter')
6936+
68916937
endfunc
68926938

68936939
"-------------------------------------------------------------------------------

src/userfunc.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,21 +1282,15 @@ get_function_body(
12821282
}
12831283

12841284
// Check for ":append", ":change", ":insert". Not for :def.
1285-
p = skip_range(p, FALSE, NULL);
1285+
char_u *tp = p = skip_range(p, FALSE, NULL);
12861286
if (!vim9_function
1287-
&& ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
1288-
|| (p[0] == 'c'
1289-
&& (!ASCII_ISALPHA(p[1]) || (p[1] == 'h'
1290-
&& (!ASCII_ISALPHA(p[2]) || (p[2] == 'a'
1291-
&& (STRNCMP(&p[3], "nge", 3) != 0
1292-
|| !ASCII_ISALPHA(p[6])))))))
1293-
|| (p[0] == 'i'
1294-
&& (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
1295-
&& (!ASCII_ISALPHA(p[2])
1296-
|| (p[2] == 's'
1297-
&& (!ASCII_ISALPHA(p[3])
1298-
|| p[3] == 'e'))))))))
1287+
&& (checkforcmd(&p, "append", 1)
1288+
|| checkforcmd(&p, "change", 1)
1289+
|| checkforcmd(&p, "insert", 1))
1290+
&& (*p == '!' || *p == '|' || IS_WHITE_NL_OR_NUL(*p)))
12991291
skip_until = vim_strnsave((char_u *)".", 1);
1292+
else
1293+
p = tp;
13001294

13011295
// Check for ":python <<EOF", ":tcl <<EOF", etc.
13021296
arg = skipwhite(skiptowhite(p));

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1607,
722724
/**/
723725
1606,
724726
/**/

0 commit comments

Comments
 (0)