Skip to content

Commit 872bee5

Browse files
committed
patch 8.2.2885: searching for \%'> does not match linewise end of line
Problem: searching for \%'> does not match linewise end of line. (Tim Chase) Solution: Match end of line if column is MAXCOL. (closes #8238)
1 parent 1e469c7 commit 872bee5

4 files changed

Lines changed: 54 additions & 17 deletions

File tree

src/regexp_bt.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,17 +3357,29 @@ regmatch(
33573357

33583358
pos = getmark_buf(rex.reg_buf, mark, FALSE);
33593359
if (pos == NULL // mark doesn't exist
3360-
|| pos->lnum <= 0 // mark isn't set in reg_buf
3361-
|| (pos->lnum == rex.lnum + rex.reg_firstlnum
3362-
? (pos->col == (colnr_T)(rex.input - rex.line)
3360+
|| pos->lnum <= 0) // mark isn't set in reg_buf
3361+
{
3362+
status = RA_NOMATCH;
3363+
}
3364+
else
3365+
{
3366+
colnr_T pos_col = pos->lnum == rex.lnum + rex.reg_firstlnum
3367+
&& pos->col == MAXCOL
3368+
? (colnr_T)STRLEN(reg_getline(
3369+
pos->lnum - rex.reg_firstlnum))
3370+
: pos->col;
3371+
3372+
if ((pos->lnum == rex.lnum + rex.reg_firstlnum
3373+
? (pos_col == (colnr_T)(rex.input - rex.line)
33633374
? (cmp == '<' || cmp == '>')
3364-
: (pos->col < (colnr_T)(rex.input - rex.line)
3375+
: (pos_col < (colnr_T)(rex.input - rex.line)
33653376
? cmp != '>'
33663377
: cmp != '<'))
33673378
: (pos->lnum < rex.lnum + rex.reg_firstlnum
33683379
? cmp != '>'
33693380
: cmp != '<')))
33703381
status = RA_NOMATCH;
3382+
}
33713383
}
33723384
break;
33733385

src/regexp_nfa.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6806,22 +6806,30 @@ nfa_regmatch(
68066806
{
68076807
pos_T *pos = getmark_buf(rex.reg_buf, t->state->val, FALSE);
68086808

6809-
// Compare the mark position to the match position.
6810-
result = (pos != NULL // mark doesn't exist
6811-
&& pos->lnum > 0 // mark isn't set in reg_buf
6812-
&& (pos->lnum == rex.lnum + rex.reg_firstlnum
6813-
? (pos->col == (colnr_T)(rex.input - rex.line)
6809+
// Compare the mark position to the match position, if the mark
6810+
// exists and mark is set in reg_buf.
6811+
if (pos != NULL && pos->lnum > 0)
6812+
{
6813+
colnr_T pos_col = pos->lnum == rex.lnum + rex.reg_firstlnum
6814+
&& pos->col == MAXCOL
6815+
? (colnr_T)STRLEN(reg_getline(
6816+
pos->lnum - rex.reg_firstlnum))
6817+
: pos->col;
6818+
6819+
result = (pos->lnum == rex.lnum + rex.reg_firstlnum
6820+
? (pos_col == (colnr_T)(rex.input - rex.line)
68146821
? t->state->c == NFA_MARK
6815-
: (pos->col < (colnr_T)(rex.input - rex.line)
6822+
: (pos_col < (colnr_T)(rex.input - rex.line)
68166823
? t->state->c == NFA_MARK_GT
68176824
: t->state->c == NFA_MARK_LT))
68186825
: (pos->lnum < rex.lnum + rex.reg_firstlnum
68196826
? t->state->c == NFA_MARK_GT
6820-
: t->state->c == NFA_MARK_LT)));
6821-
if (result)
6822-
{
6823-
add_here = TRUE;
6824-
add_state = t->state->out;
6827+
: t->state->c == NFA_MARK_LT));
6828+
if (result)
6829+
{
6830+
add_here = TRUE;
6831+
add_state = t->state->out;
6832+
}
68256833
}
68266834
break;
68276835
}

src/testdir/test_search.vim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,13 +1332,28 @@ func Test_look_behind()
13321332
bwipe!
13331333
endfunc
13341334

1335+
func Test_search_visual_area_linewise()
1336+
new
1337+
call setline(1, ['aa', 'bb', 'cc'])
1338+
exe "normal 2GV\<Esc>"
1339+
for engine in [1, 2]
1340+
exe 'set regexpengine=' .. engine
1341+
exe "normal gg/\\%'<\<CR>>"
1342+
call assert_equal([0, 2, 1, 0, 1], getcurpos(), 'engine ' .. engine)
1343+
exe "normal gg/\\%'>\<CR>"
1344+
call assert_equal([0, 2, 2, 0, 2], getcurpos(), 'engine ' .. engine)
1345+
endfor
1346+
1347+
bwipe!
1348+
set regexpengine&
1349+
endfunc
1350+
13351351
func Test_search_sentence()
13361352
new
13371353
" this used to cause a crash
1338-
call assert_fails("/\\%')", 'E486:')
1339-
call assert_fails("/", 'E486:')
13401354
/\%'(
13411355
/
1356+
bwipe
13421357
endfunc
13431358

13441359
" Test that there is no crash when there is a last search pattern but no last

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2885,
753755
/**/
754756
2884,
755757
/**/

0 commit comments

Comments
 (0)