From: Bram Moolenaar Date: Sat, 17 Jun 2017 18:08:20 +0000 (+0200) Subject: patch 8.0.0645: no error for illegal back reference in NFA engine X-Git-Tag: v8.0.0645 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ef9bbe215e13a273e74fccaddd8fc5a42c76b6e;p=vim 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 index 74a73c440..7304bd349 100644 --- 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 index 247e5e65a..a8fa64d2a 100644 --- 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 index cf85bd58a..351b119ac 100644 --- 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 index 24bb8206b..2c3c45aed 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 645, /**/ 644, /**/