aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-23 07:36:01 +0800
committerGitHub <noreply@github.com>2023-01-23 07:36:01 +0800
commit0f633ff494b5b39b5ca410e75ea3357c79657bcd (patch)
tree819f021f62068d668993e3e45c9d6bda3053a909
parent1b642648f6c94c0bc0db521714a922207ef8bbc5 (diff)
downloadrneovim-0f633ff494b5b39b5ca410e75ea3357c79657bcd.tar.gz
rneovim-0f633ff494b5b39b5ca410e75ea3357c79657bcd.tar.bz2
rneovim-0f633ff494b5b39b5ca410e75ea3357c79657bcd.zip
vim-patch:9.0.1233: search() loops forever if "skip" is TRUE for all matches (#21956)
Problem: search() loops forever if "skip" is TRUE for all matches. Solution: Keep the position of the first match. https://github.com/vim/vim/commit/3d79f0a4309995956bd8889940cca22f7a15881d Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r--src/nvim/eval/funcs.c4
-rw-r--r--src/nvim/testdir/test_search.vim16
2 files changed, 19 insertions, 1 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 4692035dd9..c64aad659f 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -6239,7 +6239,9 @@ static int search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp)
// didn't find it or no skip argument
break;
}
- firstpos = pos;
+ if (firstpos.lnum == 0) {
+ firstpos = pos;
+ }
// If the skip expression matches, ignore this match.
{
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index a9cad3ed44..885043accf 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -1377,6 +1377,22 @@ func Test_subst_word_under_cursor()
set noincsearch
endfunc
+func Test_search_skip_all_matches()
+ enew
+ call setline(1, ['no match here',
+ \ 'match this line',
+ \ 'nope',
+ \ 'match in this line',
+ \ 'last line',
+ \ ])
+ call cursor(1, 1)
+ let lnum = search('this', '', 0, 0, 'getline(".") =~ "this line"')
+ " Only check that no match is found. Previously it searched forever.
+ call assert_equal(0, lnum)
+
+ bwipe!
+endfunc
+
func Test_search_undefined_behaviour()
CheckFeature terminal