Skip to content

Commit

Permalink
patch 8.2.4978: no error if engine selection atom is not at the start
Browse files Browse the repository at this point in the history
Problem:    No error if engine selection atom is not at the start.
Solution:   Give an error. (Christian Brabandt, closes #10439)
  • Loading branch information
chrisbra authored and brammool committed May 18, 2022
1 parent e2bd860 commit 360da40
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/doc/pattern.txt
Expand Up @@ -379,7 +379,7 @@ Vim includes two regexp engines:
1. An old, backtracking engine that supports everything.
2. A new, NFA engine that works much faster on some patterns, possibly slower
on some patterns.

*E1281*
Vim will automatically select the right engine for you. However, if you run
into a problem or want to specifically select one engine or the other, you can
prepend one of the following to the pattern:
Expand Down
2 changes: 2 additions & 0 deletions src/errors.h
Expand Up @@ -3277,3 +3277,5 @@ EXTERN char e_missing_close_curly_str[]
EXTERN char e_illegal_character_in_word[]
INIT(= N_("E1280: Illegal character in word"));
#endif
EXTERN char e_atom_engine_must_be_at_start_of_pattern[]
INIT(= N_("E1281: Atom '\\%%#=%c' must be at the start of the pattern"));
8 changes: 8 additions & 0 deletions src/regexp_bt.c
Expand Up @@ -1503,6 +1503,14 @@ regatom(int *flagp)
break;

case '#':
if (regparse[0] == '=' && regparse[1] >= 48
&& regparse[1] <= 50)
{
// misplaced \%#=1
semsg(_(e_atom_engine_must_be_at_start_of_pattern),
regparse[1]);
return FAIL;
}
ret = regnode(CURSOR);
break;

Expand Down
8 changes: 8 additions & 0 deletions src/regexp_nfa.c
Expand Up @@ -1592,6 +1592,14 @@ nfa_regatom(void)
break;

case '#':
if (regparse[0] == '=' && regparse[1] >= 48
&& regparse[1] <= 50)
{
// misplaced \%#=1
semsg(_(e_atom_engine_must_be_at_start_of_pattern),
regparse[1]);
return FAIL;
}
EMIT(NFA_CURSOR);
break;

Expand Down
18 changes: 18 additions & 0 deletions src/testdir/test_regexp_latin.vim
Expand Up @@ -1096,4 +1096,22 @@ func Test_using_invalid_visual_position()
bwipe!
endfunc

func Test_using_two_engines_pattern()
new
call setline(1, ['foobar=0', 'foobar=1', 'foobar=2'])
" \%#= at the end of the pattern
for i in range(0, 2)
call cursor( (i+1), 7)
call assert_fails("%s/foobar\\%#=" .. i, 'E1281:')
endfor

" \%#= at the start of the pattern
for i in range(0, 2)
call cursor( (i+1), 7)
exe ":%s/\\%#=" .. i .. "foobar=" .. i .. "/xx"
endfor
call assert_equal(['xx', 'xx', 'xx'], getline(1, '$'))
bwipe!
endfunc

" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -746,6 +746,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4978,
/**/
4977,
/**/
Expand Down

0 comments on commit 360da40

Please sign in to comment.