To: vim_dev@googlegroups.com Subject: Patch 8.2.4978 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4978 Problem: No error if engine selection atom is not at the start. Solution: Give an error. (Christian Brabandt, closes #10439) Files: runtime/doc/pattern.txt, src/errors.h, src/regexp_bt.c, src/regexp_nfa.c, src/testdir/test_regexp_latin.vim *** ../vim-8.2.4977/runtime/doc/pattern.txt 2021-07-05 19:14:54.396221575 +0100 --- runtime/doc/pattern.txt 2022-05-18 14:32:18.308895247 +0100 *************** *** 375,381 **** 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. ! 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: --- 379,385 ---- 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: *** ../vim-8.2.4977/src/errors.h 2022-05-10 17:51:51.391754834 +0100 --- src/errors.h 2022-05-18 14:32:18.308895247 +0100 *************** *** 3277,3279 **** --- 3277,3281 ---- 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")); *** ../vim-8.2.4977/src/regexp_bt.c 2022-04-05 14:00:28.860929090 +0100 --- src/regexp_bt.c 2022-05-18 15:03:06.803577055 +0100 *************** *** 1503,1508 **** --- 1503,1516 ---- 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; *** ../vim-8.2.4977/src/regexp_nfa.c 2022-04-05 14:00:28.860929090 +0100 --- src/regexp_nfa.c 2022-05-18 15:03:30.823559859 +0100 *************** *** 1592,1597 **** --- 1592,1605 ---- 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; *** ../vim-8.2.4977/src/testdir/test_regexp_latin.vim 2022-04-05 14:00:28.864929097 +0100 --- src/testdir/test_regexp_latin.vim 2022-05-18 15:00:48.787675348 +0100 *************** *** 1096,1099 **** --- 1096,1117 ---- 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 *** ../vim-8.2.4977/src/version.c 2022-05-18 13:11:53.163464115 +0100 --- src/version.c 2022-05-18 14:38:17.360630088 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4978, /**/ -- A computer without Windows is like a fish without a bicycle. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///