]> granicus.if.org Git - vim/commitdiff
patch 9.0.0414: matchstr() still does not match column offset v9.0.0414
authorBram Moolenaar <Bram@vim.org>
Thu, 8 Sep 2022 11:17:06 +0000 (12:17 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 8 Sep 2022 11:17:06 +0000 (12:17 +0100)
Problem:    matchstr() still does not match column offset when done after a
            text search.
Solution:   Only use the line number for a multi-line search.  Fix the test.
            (closes #10938)

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

index e3e7a18016b2034dfcb76f02be736186675c3605..520656798fae8d4ae73c2ca2b3903223eafb0dc0 100644 (file)
@@ -3441,11 +3441,13 @@ regmatch(
          case RE_VCOL:
            {
                win_T       *wp = rex.reg_win == NULL ? curwin : rex.reg_win;
-               linenr_T    lnum = rex.reg_firstlnum + rex.lnum;
-               long_u      vcol = 0;
+               linenr_T    lnum = REG_MULTI ? rex.reg_firstlnum + rex.lnum : 1;
+               long_u      vcol;
 
-               if (lnum >= 0 && lnum <= wp->w_buffer->b_ml.ml_line_count)
-                   vcol = (long_u)win_linetabsize(wp, lnum, rex.line,
+               if (REG_MULTI && (lnum <= 0
+                                  || lnum > wp->w_buffer->b_ml.ml_line_count))
+                   lnum = 1;
+               vcol = (long_u)win_linetabsize(wp, lnum, rex.line,
                                              (colnr_T)(rex.input - rex.line));
                if (!re_num_cmp(vcol + 1, scan))
                    status = RA_NOMATCH;
index b39848927298836aeeb2cd3905105256267740d7..fc1a993394054cb70425442dcbf826a3937b3f0c 100644 (file)
@@ -6775,12 +6775,14 @@ nfa_regmatch(
                    }
                    if (!result)
                    {
-                       linenr_T    lnum = rex.reg_firstlnum + rex.lnum;
-                       long_u      vcol = 0;
-
-                       if (lnum >= 0
-                                  && lnum <= wp->w_buffer->b_ml.ml_line_count)
-                           vcol = (long_u)win_linetabsize(wp, lnum,
+                       linenr_T    lnum = REG_MULTI
+                                           ? rex.reg_firstlnum + rex.lnum : 1;
+                       long_u      vcol;
+
+                       if (REG_MULTI && (lnum <= 0
+                                  || lnum > wp->w_buffer->b_ml.ml_line_count))
+                           lnum = 1;
+                       vcol = (long_u)win_linetabsize(wp, lnum,
                                                                rex.line, col);
                        result = nfa_re_num_cmp(t->state->val, op, vcol + 1);
                    }
index 6f3ffe23ff26edd5df9fafdb6b9b1a20e3118518..8df357fd4484fb2bdba58195e97a914b151f01a3 100644 (file)
@@ -1145,7 +1145,13 @@ def Test_compare_columns()
 enddef
 
 def Test_compare_column_matchstr()
+  # do some search in text to set the line number, it should be ignored in
+  # matchstr().
   enew
+  setline(1, ['one', 'two', 'three'])
+  :3 
+  :/ee
+  bwipe!
   set re=1
   call assert_equal('aaa', matchstr('aaaaaaaaaaaaaaaaaaaa', '.*\%<5v'))
   set re=2
index bff11c710dfefbf54200983667ca676314b2fb6b..5fdf817a58215785a3430eec6f675d6596060c0b 100644 (file)
@@ -703,6 +703,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    414,
 /**/
     413,
 /**/