1
0
forked from aniani/vim

patch 8.2.4345: <amatch> is expanded like a file name for DirChangedPre

Problem:    <amatch> is expanded like a file name for DirChangedPre.
Solution:   Do not expand <amatch>. (closes #9742)  Also for the User event.
This commit is contained in:
Bram Moolenaar
2022-02-11 16:30:12 +00:00
parent 14f23122bf
commit f6246f51e3
3 changed files with 15 additions and 3 deletions

View File

@@ -2043,7 +2043,7 @@ apply_autocmds_group(
{ {
sfname = vim_strsave(fname); sfname = vim_strsave(fname);
// Don't try expanding FileType, Syntax, FuncUndefined, WindowID, // Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
// ColorScheme, QuickFixCmd* or DirChanged // ColorScheme, QuickFixCmd*, DirChanged and similar.
if (event == EVENT_FILETYPE if (event == EVENT_FILETYPE
|| event == EVENT_SYNTAX || event == EVENT_SYNTAX
|| event == EVENT_CMDLINECHANGED || event == EVENT_CMDLINECHANGED
@@ -2061,7 +2061,9 @@ apply_autocmds_group(
|| event == EVENT_OPTIONSET || event == EVENT_OPTIONSET
|| event == EVENT_QUICKFIXCMDPOST || event == EVENT_QUICKFIXCMDPOST
|| event == EVENT_DIRCHANGED || event == EVENT_DIRCHANGED
|| event == EVENT_DIRCHANGEDPRE
|| event == EVENT_MODECHANGED || event == EVENT_MODECHANGED
|| event == EVENT_USER
|| event == EVENT_WINCLOSED) || event == EVENT_WINCLOSED)
{ {
fname = vim_strsave(fname); fname = vim_strsave(fname);

View File

@@ -1899,6 +1899,14 @@ func Test_autocommand_all_events()
call assert_fails('au! * x bwipe', 'E1155:') call assert_fails('au! * x bwipe', 'E1155:')
endfunc endfunc
func Test_autocmd_user()
au User MyEvent let s:res = [expand("<afile>"), expand("<amatch>")]
doautocmd User MyEvent
call assert_equal(['MyEvent', 'MyEvent'], s:res)
au! User
unlet s:res
endfunc
function s:Before_test_dirchanged() function s:Before_test_dirchanged()
augroup test_dirchanged augroup test_dirchanged
autocmd! autocmd!
@@ -1922,11 +1930,11 @@ endfunc
function Test_dirchanged_global() function Test_dirchanged_global()
call s:Before_test_dirchanged() call s:Before_test_dirchanged()
autocmd test_dirchanged DirChangedPre global call add(s:li, "pre cd " .. v:event.directory) autocmd test_dirchanged DirChangedPre global call add(s:li, expand("<amatch>") .. " pre cd " .. v:event.directory)
autocmd test_dirchanged DirChanged global call add(s:li, "cd:") autocmd test_dirchanged DirChanged global call add(s:li, "cd:")
autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>")) autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>"))
call chdir(s:dir_foo) call chdir(s:dir_foo)
let expected = ["pre cd " .. s:dir_foo, "cd:", s:dir_foo] let expected = ["global pre cd " .. s:dir_foo, "cd:", s:dir_foo]
call assert_equal(expected, s:li) call assert_equal(expected, s:li)
call chdir(s:dir_foo) call chdir(s:dir_foo)
call assert_equal(expected, s:li) call assert_equal(expected, s:li)

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4345,
/**/ /**/
4344, 4344,
/**/ /**/