Problem: search() loops forever if "skip" is TRUE for all matches.
Solution: Keep the position of the first match.
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.
{
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1233,
/**/
1232,
/**/