changeset 30142:22a5ccc0d634 v9.0.0407

patch 9.0.0407: matchstr() does match column offset Commit: https://github.com/vim/vim/commit/75a115e8d632e96b4f45dc5145ba261876a83dcf Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 7 18:21:24 2022 +0100 patch 9.0.0407: matchstr() does match column offset Problem: matchstr() does match column offset. (Yasuhiro Matsumoto) Solution: Accept line number zero. (closes https://github.com/vim/vim/issues/10938)
author Bram Moolenaar <Bram@vim.org>
date Wed, 07 Sep 2022 19:30:03 +0200
parents 0d7a4958293c
children fc3456fdd67e
files src/regexp_bt.c src/regexp_nfa.c src/testdir/test_regexp_latin.vim src/version.c
diffstat 4 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/regexp_bt.c
+++ b/src/regexp_bt.c
@@ -3444,7 +3444,7 @@ regmatch(
 		linenr_T    lnum = rex.reg_firstlnum + rex.lnum;
 		long_u	    vcol = 0;
 
-		if (lnum > 0 && lnum <= wp->w_buffer->b_ml.ml_line_count)
+		if (lnum >= 0 && lnum <= wp->w_buffer->b_ml.ml_line_count)
 		    vcol = (long_u)win_linetabsize(wp, lnum, rex.line,
 					      (colnr_T)(rex.input - rex.line));
 		if (!re_num_cmp(vcol + 1, scan))
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -6778,7 +6778,7 @@ nfa_regmatch(
 			linenr_T    lnum = rex.reg_firstlnum + rex.lnum;
 			long_u	    vcol = 0;
 
-			if (lnum > 0
+			if (lnum >= 0
 				   && lnum <= wp->w_buffer->b_ml.ml_line_count)
 			    vcol = (long_u)win_linetabsize(wp, lnum,
 								rex.line, col);
--- a/src/testdir/test_regexp_latin.vim
+++ b/src/testdir/test_regexp_latin.vim
@@ -30,11 +30,13 @@ endfunc
 func Test_equivalence_re1()
   set re=1
   call s:equivalence_test()
+  set re=0
 endfunc
 
 func Test_equivalence_re2()
   set re=2
   call s:equivalence_test()
+  set re=0
 endfunc
 
 func Test_recursive_substitute()
@@ -67,6 +69,7 @@ func Test_eow_with_optional()
     let actual = matchlist('abc def', '\(abc\>\)\?\s*\(def\)')
     call assert_equal(expected, actual)
   endfor
+  set re=0
 endfunc
 
 func Test_backref()
@@ -1141,4 +1144,14 @@ def Test_compare_columns()
   prop_type_delete('name')
 enddef
 
+def Test_compare_column_matchstr()
+  enew
+  set re=1
+  call assert_equal('aaa', matchstr('aaaaaaaaaaaaaaaaaaaa', '.*\%<5v'))
+  set re=2
+  call assert_equal('aaa', matchstr('aaaaaaaaaaaaaaaaaaaa', '.*\%<5v'))
+  set re=0
+enddef
+
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    407,
+/**/
     406,
 /**/
     405,