]> granicus.if.org Git - vim/commitdiff
patch 8.2.2885: searching for \%'> does not match linewise end of line v8.2.2885
authorBram Moolenaar <Bram@vim.org>
Mon, 24 May 2021 20:56:15 +0000 (22:56 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 24 May 2021 20:56:15 +0000 (22:56 +0200)
Problem:    searching for \%'> does not match linewise end of line. (Tim Chase)
Solution:   Match end of line if column is MAXCOL. (closes #8238)

src/regexp_bt.c
src/regexp_nfa.c
src/testdir/test_search.vim
src/version.c

index afea5e4cb5b8486afebd6b77ea91e69180cb505c..70ddfe986f0fc60f62c392ed8ce8eb9e40c7ca34 100644 (file)
@@ -3357,17 +3357,29 @@ regmatch(
 
                pos = getmark_buf(rex.reg_buf, mark, FALSE);
                if (pos == NULL              // mark doesn't exist
-                       || pos->lnum <= 0    // mark isn't set in reg_buf
-                       || (pos->lnum == rex.lnum + rex.reg_firstlnum
-                               ? (pos->col == (colnr_T)(rex.input - rex.line)
+                       || pos->lnum <= 0)   // mark isn't set in reg_buf
+               {
+                   status = RA_NOMATCH;
+               }
+               else
+               {
+                   colnr_T pos_col = pos->lnum == rex.lnum + rex.reg_firstlnum
+                                                         && pos->col == MAXCOL
+                                     ? (colnr_T)STRLEN(reg_getline(
+                                               pos->lnum - rex.reg_firstlnum))
+                                     : pos->col;
+
+                   if ((pos->lnum == rex.lnum + rex.reg_firstlnum
+                               ? (pos_col == (colnr_T)(rex.input - rex.line)
                                    ? (cmp == '<' || cmp == '>')
-                                   : (pos->col < (colnr_T)(rex.input - rex.line)
+                                   : (pos_col < (colnr_T)(rex.input - rex.line)
                                        ? cmp != '>'
                                        : cmp != '<'))
                                : (pos->lnum < rex.lnum + rex.reg_firstlnum
                                    ? cmp != '>'
                                    : cmp != '<')))
                    status = RA_NOMATCH;
+               }
            }
            break;
 
index a519b85374fd873153814856a8132b779d6bed76..2ed18685d9ddd311aac0b6ce4644ce2e16a15c84 100644 (file)
@@ -6806,22 +6806,30 @@ nfa_regmatch(
              {
                pos_T   *pos = getmark_buf(rex.reg_buf, t->state->val, FALSE);
 
-               // Compare the mark position to the match position.
-               result = (pos != NULL                // mark doesn't exist
-                       && pos->lnum > 0    // mark isn't set in reg_buf
-                       && (pos->lnum == rex.lnum + rex.reg_firstlnum
-                               ? (pos->col == (colnr_T)(rex.input - rex.line)
+               // Compare the mark position to the match position, if the mark
+               // exists and mark is set in reg_buf.
+               if (pos != NULL && pos->lnum > 0)
+               {
+                   colnr_T pos_col = pos->lnum == rex.lnum + rex.reg_firstlnum
+                                                         && pos->col == MAXCOL
+                                     ? (colnr_T)STRLEN(reg_getline(
+                                               pos->lnum - rex.reg_firstlnum))
+                                     : pos->col;
+
+                   result = (pos->lnum == rex.lnum + rex.reg_firstlnum
+                               ? (pos_col == (colnr_T)(rex.input - rex.line)
                                    ? t->state->c == NFA_MARK
-                                   : (pos->col < (colnr_T)(rex.input - rex.line)
+                                   : (pos_col < (colnr_T)(rex.input - rex.line)
                                        ? t->state->c == NFA_MARK_GT
                                        : t->state->c == NFA_MARK_LT))
                                : (pos->lnum < rex.lnum + rex.reg_firstlnum
                                    ? t->state->c == NFA_MARK_GT
-                                   : t->state->c == NFA_MARK_LT)));
-               if (result)
-               {
-                   add_here = TRUE;
-                   add_state = t->state->out;
+                                   : t->state->c == NFA_MARK_LT));
+                   if (result)
+                   {
+                       add_here = TRUE;
+                       add_state = t->state->out;
+                   }
                }
                break;
              }
index e7c9ac4747b6d2afe2a64fdf59622f45b41bff2e..b265e97de1352cb46d4be380c9289d901216cc2e 100644 (file)
@@ -1332,13 +1332,28 @@ func Test_look_behind()
   bwipe!
 endfunc
 
+func Test_search_visual_area_linewise()
+  new
+  call setline(1, ['aa', 'bb', 'cc'])
+  exe "normal 2GV\<Esc>"
+  for engine in [1, 2]
+    exe 'set regexpengine=' .. engine
+    exe "normal gg/\\%'<\<CR>>"
+    call assert_equal([0, 2, 1, 0, 1], getcurpos(), 'engine ' .. engine)
+    exe "normal gg/\\%'>\<CR>"
+    call assert_equal([0, 2, 2, 0, 2], getcurpos(), 'engine ' .. engine)
+  endfor
+
+  bwipe!
+  set regexpengine&
+endfunc
+
 func Test_search_sentence()
   new
   " this used to cause a crash
-  call assert_fails("/\\%')", 'E486:')
-  call assert_fails("/", 'E486:')
   /\%'(
   /
+  bwipe
 endfunc
 
 " Test that there is no crash when there is a last search pattern but no last
index c0729b2cbf880486f9e88c3e565cadd49aec771c..c841e6b501789a941002b5950e34caa179bd0f85 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2885,
 /**/
     2884,
 /**/