]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4978: no error if engine selection atom is not at the start v8.2.4978
authorChristian Brabandt <cb@256bit.org>
Wed, 18 May 2022 14:04:02 +0000 (15:04 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 18 May 2022 14:04:02 +0000 (15:04 +0100)
Problem:    No error if engine selection atom is not at the start.
Solution:   Give an error. (Christian Brabandt, closes #10439)

runtime/doc/pattern.txt
src/errors.h
src/regexp_bt.c
src/regexp_nfa.c
src/testdir/test_regexp_latin.vim
src/version.c

index 7de1824185040d638584a26a5f89d8cc3739a440..50fd53c8532edb36a7b99678b2a82ed1c601519d 100644 (file)
@@ -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:
index 526c5f7a55ff63751bce1eb4984228bfd15a9a63..7a21ceeca891bb5ae2d6c46745ba02960cf8d785 100644 (file)
@@ -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"));
index 18bad80548158d0d28c628450dec849462c58f4c..698ff043ea04de76b76099fb21a1a97c8bba8811 100644 (file)
@@ -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;
 
index 2c79a49e499ea0caa13f78d3abe476add22c4221..511b90483422a958c2e194243f9631971ae274c1 100644 (file)
@@ -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;
 
index 0b288f69fd586117d1ff9b8fa9163e017286fcec..1fe4699d1064e98e49250cc3a2b7aea4f7b9a96c 100644 (file)
@@ -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
index 782642b5d5a1ce13c49729164c00512fccc2b827..854de459729af4f146f12af58d3c371b676f77f4 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4978,
 /**/
     4977,
 /**/