]> granicus.if.org Git - vim/commitdiff
patch 9.0.1233: search() loops forever if "skip" is TRUE for all matches v9.0.1233
authorBram Moolenaar <Bram@vim.org>
Sun, 22 Jan 2023 20:14:26 +0000 (20:14 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 22 Jan 2023 20:14:26 +0000 (20:14 +0000)
Problem:    search() loops forever if "skip" is TRUE for all matches.
Solution:   Keep the position of the first match.

src/evalfunc.c
src/testdir/test_search.vim
src/version.c

index 5b25e97cbe52be7e49d7ff41f1a2f9c5d90fac3c..7b34e3925b42f33e29cecbb116f219a0003e8b89 100644 (file)
@@ -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.
        {
index 074ab1546762baa9e1a2d1aa0b05737dfe28d40f..ef4475165982b33c1505c0c15c771615d4a699a8 100644 (file)
@@ -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
 
index 6604e0164829779f53d81609aeb6f2f69edb7e94..293e17626383fa82ad7d669d7519db4a8f600a2f 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1233,
 /**/
     1232,
 /**/