# HG changeset patch # User Christian Brabandt # Date 1497723303 -7200 # Node ID 14b6b79d685b83054fdb85fc8c18dbecc05b6907 # Parent a1e8fabe521cdff9d95d3cad1279c84ed33893ab patch 8.0.0645: no error for illegal back reference in NFA engine commit https://github.com/vim/vim/commit/1ef9bbe215e13a273e74fccaddd8fc5a42c76b6e Author: Bram Moolenaar Date: Sat Jun 17 20:08:20 2017 +0200 patch 8.0.0645: no error for illegal back reference in NFA engine Problem: The new regexp engine does not give an error for using a back reference where it is not allowed. (Dominique Pelle) Solution: Check the back reference like the old engine. (closes #1774) diff --git a/src/regexp.c b/src/regexp.c --- a/src/regexp.c +++ b/src/regexp.c @@ -1294,6 +1294,34 @@ skip_regexp( return p; } +/* + * Return TRUE if the back reference is legal. We must have seen the close + * brace. + * TODO: Should also check that we don't refer to something that is repeated + * (+*=): what instance of the repetition should we match? + */ + static int +seen_endbrace(int refnum) +{ + if (!had_endbrace[refnum]) + { + char_u *p; + + /* Trick: check if "@<=" or "@ 0.1) diff --git a/src/testdir/test_regexp_latin.vim b/src/testdir/test_regexp_latin.vim --- a/src/testdir/test_regexp_latin.vim +++ b/src/testdir/test_regexp_latin.vim @@ -62,3 +62,13 @@ func Test_eow_with_optional() call assert_equal(expected, actual) endfor endfunc + +func Test_backref() + new + call setline(1, ['one', 'two', 'three', 'four', 'five']) + call assert_equal(3, search('\%#=1\(e\)\1')) + call assert_equal(3, search('\%#=2\(e\)\1')) + call assert_fails('call search("\\%#=1\\(e\\1\\)")', 'E65:') + call assert_fails('call search("\\%#=2\\(e\\1\\)")', 'E65:') + bwipe! +endfunc diff --git a/src/testdir/test_statusline.vim b/src/testdir/test_statusline.vim --- a/src/testdir/test_statusline.vim +++ b/src/testdir/test_statusline.vim @@ -223,7 +223,7 @@ func Test_statusline() set statusline=ab%(cd%q%)de call assert_match('^abde\s*$', s:get_statusline()) copen - call assert_match('^abcd\[Quickfix List\1]de\s*$', s:get_statusline()) + call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline()) cclose " %#: Set highlight group. The name must follow and then a # again. diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -765,6 +765,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 645, +/**/ 644, /**/ 643,