summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-01-22 20:14:26 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-22 20:14:26 +0000
commit3d79f0a4309995956bd8889940cca22f7a15881d (patch)
treeac4f9160853ae5d514d5cc737f44e301b88fb24d
parentd343c60df4b0adc6b1baac4d68a72a735ac21dc4 (diff)
downloadvim-git-3d79f0a4309995956bd8889940cca22f7a15881d.tar.gz
patch 9.0.1233: search() loops forever if "skip" is TRUE for all matchesv9.0.1233
Problem: search() loops forever if "skip" is TRUE for all matches. Solution: Keep the position of the first match.
-rw-r--r--src/evalfunc.c3
-rw-r--r--src/testdir/test_search.vim16
-rw-r--r--src/version.c2
3 files changed, 20 insertions, 1 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 5b25e97cb..7b34e3925 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -8794,7 +8794,8 @@ search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp)
if (subpatnum == FAIL || !use_skip)
// 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/testdir/test_search.vim b/src/testdir/test_search.vim
index 074ab1546..ef4475165 100644
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -1411,6 +1411,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
diff --git a/src/version.c b/src/version.c
index 6604e0164..293e17626 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1233,
+/**/
1232,
/**/
1231,