diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-07-17 10:38:40 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2024-07-17 11:04:55 +0800 |
commit | ccdbab7810bd40a44a0a502d478b0d06073388e9 (patch) | |
tree | ffc8f476b62855ecff99131381b5195e61544758 | |
parent | dce615bc425795ad65f96ed1879ba37ff6a030d8 (diff) | |
download | rneovim-ccdbab7810bd40a44a0a502d478b0d06073388e9.tar.gz rneovim-ccdbab7810bd40a44a0a502d478b0d06073388e9.tar.bz2 rneovim-ccdbab7810bd40a44a0a502d478b0d06073388e9.zip |
vim-patch:9.0.0407: matchstr() does match column offset
Problem: matchstr() does match column offset. (Yasuhiro Matsumoto)
Solution: Accept line number zero. (closes vim/vim#10938)
https://github.com/vim/vim/commit/75a115e8d632e96b4f45dc5145ba261876a83dcf
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/regexp.c | 4 | ||||
-rw-r--r-- | test/old/testdir/test_regexp_latin.vim | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 52420cf64f..22859a1e54 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -6259,7 +6259,7 @@ static bool regmatch(uint8_t *scan, const proftime_T *tm, int *timed_out) linenr_T lnum = rex.reg_firstlnum + rex.lnum; int 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 = win_linetabsize(wp, lnum, (char *)rex.line, (colnr_T)(rex.input - rex.line)); } @@ -15108,7 +15108,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm linenr_T lnum = rex.reg_firstlnum + rex.lnum; int 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 = win_linetabsize(wp, lnum, (char *)rex.line, col); } assert(t->state->val >= 0); diff --git a/test/old/testdir/test_regexp_latin.vim b/test/old/testdir/test_regexp_latin.vim index de73ae633f..754fa8c868 100644 --- a/test/old/testdir/test_regexp_latin.vim +++ b/test/old/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() @@ -1147,4 +1150,14 @@ endfunc " prop_type_delete('name') " enddef +func 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 +endfunc + + " vim: shiftwidth=2 sts=2 expandtab |