patch 9.1.0692: Wrong patlen value in ex_substitute() Commit: https://github.com/vim/vim/commit/d1c8d2de4b9fa44b3d2b39b7ed8b92846c5502b7 Author: zeertzjq <zeert...@outlook.com> Date: Sat Aug 24 11:33:39 2024 +0200
patch 9.1.0692: Wrong patlen value in ex_substitute() Problem: Wrong patlen value in ex_substitute() (after 9.1.0426). Solution: Compute patlen after finding end separator. (zeertzjq) Add a more explicit test. The test already passes as the only case where a overlarge patlen value matters was fixed by patch 9.1.0689. closes: #15565 Signed-off-by: zeertzjq <zeert...@outlook.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/ex_cmds.c b/src/ex_cmds.c index b2aaf1cab..acddd9c38 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -3841,11 +3841,11 @@ ex_substitute(exarg_T *eap) which_pat = RE_LAST; // use last used regexp delimiter = *cmd++; // remember delimiter character pat = cmd; // remember start of search pat - patlen = STRLEN(pat); cmd = skip_regexp_ex(cmd, delimiter, magic_isset(), &eap->arg, NULL, NULL); if (cmd[0] == delimiter) // end delimiter found *cmd++ = NUL; // replace it with a NUL + patlen = STRLEN(pat); } /* diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index 1a9f49bfe..708aca2a8 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -1747,6 +1747,37 @@ func Test_search_with_no_last_pat() call delete('Xresult') endfunc +" Test for using the last substitute pattern without last search pattern. +func Test_search_with_last_substitute_pat() + let lines =<< trim [SCRIPT] + new + set shortmess+=S + call setline(1, repeat(['foofoo'], 3)) + %s/foo/bar/ + call assert_equal(repeat(['barfoo'], 3), getline(1, '$')) + + call cursor(1, 1) + call assert_equal("/foo", execute('call feedkeys("/ ", "tx")', '')->trim()) + call assert_equal([0, 1, 4, 0], getpos('.')) + + if has('rightleft') + set rightleft rightleftcmd=search + call cursor(1, 1) + call assert_equal("oof/", execute('call feedkeys("/ ", "tx")', '')->trim()) + call assert_equal([0, 1, 4, 0], getpos('.')) + endif + + call writefile(v:errors, 'Xresult') + qall! + [SCRIPT] + call writefile(lines, 'Xscript', 'D') + + if RunVim([], [], '--clean -S Xscript') + call assert_equal([], readfile('Xresult')) + endif + call delete('Xresult') +endfunc + " Test for using tilde (~) atom in search. This should use the last used " substitute pattern func Test_search_tilde_pat() diff --git a/src/version.c b/src/version.c index 3a34efed5..79c81c107 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 692, /**/ 691, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/E1shnKX-004nhd-12%40256bit.org.