summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Brabandt <cb@256bit.org>2022-05-18 15:04:02 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-18 15:04:02 +0100
commit360da40b47a84ee8586c3b5d062f8c64a2ac9cc6 (patch)
tree0be4a080f9ef8f262bf93da97dd512de6cfdea98 /src
parente2bd8600b873d2cd1f9d667c28cba8b1dba18839 (diff)
patch 8.2.4978: no error if engine selection atom is not at the startv8.2.4978
Problem: No error if engine selection atom is not at the start. Solution: Give an error. (Christian Brabandt, closes #10439)
Diffstat (limited to 'src')
-rw-r--r--src/errors.h2
-rw-r--r--src/regexp_bt.c8
-rw-r--r--src/regexp_nfa.c8
-rw-r--r--src/testdir/test_regexp_latin.vim18
-rw-r--r--src/version.c2
5 files changed, 38 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
index 526c5f7a55..7a21ceeca8 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -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"));
diff --git a/src/regexp_bt.c b/src/regexp_bt.c
index 18bad80548..698ff043ea 100644
--- a/src/regexp_bt.c
+++ b/src/regexp_bt.c
@@ -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;
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index 2c79a49e49..511b904834 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -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;
diff --git a/src/testdir/test_regexp_latin.vim b/src/testdir/test_regexp_latin.vim
index 0b288f69fd..1fe4699d10 100644
--- a/src/testdir/test_regexp_latin.vim
+++ b/src/testdir/test_regexp_latin.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 782642b5d5..854de45972 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4978,
+/**/
4977,
/**/
4976,