vim-patch:7.4.289 #752

Problem:    Pattern with repeated backreference does not match with new regexp
            engine. (Urtica Dioica)
Solution:   Also check the end of a submatch when deciding to put a state in
            the state list.

https://code.google.com/p/vim/source/detail?r=99374096a76b96d1128f5e6aa1fa92b4ba70fee9
This commit is contained in:
oni-link
2014-05-22 12:25:46 +02:00
committed by Justin M. Keyes
parent 8638578bf3
commit 2085acf478
4 changed files with 43 additions and 3 deletions

View File

@@ -3516,9 +3516,8 @@ static void copy_ze_off(regsub_T *to, regsub_T *from)
} }
} }
/* // Return TRUE if "sub1" and "sub2" have the same start positions.
* Return TRUE if "sub1" and "sub2" have the same start positions. // When using back-references also check the end position.
*/
static int sub_equal(regsub_T *sub1, regsub_T *sub2) static int sub_equal(regsub_T *sub1, regsub_T *sub2)
{ {
int i; int i;
@@ -3544,6 +3543,26 @@ static int sub_equal(regsub_T *sub1, regsub_T *sub2)
if (s1 != -1 && sub1->list.multi[i].start.col if (s1 != -1 && sub1->list.multi[i].start.col
!= sub2->list.multi[i].start.col) != sub2->list.multi[i].start.col)
return FALSE; return FALSE;
if (nfa_has_backref) {
if (i < sub1->in_use) {
s1 = sub1->list.multi[i].end.lnum;
} else {
s1 = -1;
}
if (i < sub2->in_use) {
s2 = sub2->list.multi[i].end.lnum;
} else {
s2 = -1;
}
if (s1 != s2) {
return FALSE;
}
if (s1 != -1
&& sub1->list.multi[i].end.col != sub2->list.multi[i].end.col) {
return FALSE;
}
}
} }
} else { } else {
for (i = 0; i < todo; ++i) { for (i = 0; i < todo; ++i) {
@@ -3557,6 +3576,22 @@ static int sub_equal(regsub_T *sub1, regsub_T *sub2)
sp2 = NULL; sp2 = NULL;
if (sp1 != sp2) if (sp1 != sp2)
return FALSE; return FALSE;
if (nfa_has_backref) {
if (i < sub1->in_use) {
sp1 = sub1->list.line[i].end;
} else {
sp1 = NULL;
}
if (i < sub2->in_use) {
sp2 = sub2->list.line[i].end;
} else {
sp2 = NULL;
}
if (sp1 != sp2) {
return FALSE;
}
}
} }
} }

View File

@@ -407,6 +407,7 @@ STARTTEST
:call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<=$', 'foo.bat/foo.bat', 'foo.bat/foo.bat', 'bat', 'bat']) :call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<=$', 'foo.bat/foo.bat', 'foo.bat/foo.bat', 'bat', 'bat'])
:call add(tl, [2, '\\\@<!\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}', '2013-06-27${0}', '${0}', '0']) :call add(tl, [2, '\\\@<!\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}', '2013-06-27${0}', '${0}', '0'])
:call add(tl, [2, '^\(a*\)\1$', 'aaaaaaaa', 'aaaaaaaa', 'aaaa']) :call add(tl, [2, '^\(a*\)\1$', 'aaaaaaaa', 'aaaaaaaa', 'aaaa'])
:call add(tl, [2, '^\(a\{-2,}\)\1\+$', 'aaaaaaaaa', 'aaaaaaaaa', 'aaa'])
:" :"
:"""" Look-behind with limit :"""" Look-behind with limit
:call add(tl, [2, '<\@<=span.', 'xxspanxx<spanyyy', 'spany']) :call add(tl, [2, '<\@<=span.', 'xxspanxx<spanyyy', 'spany'])

View File

@@ -947,6 +947,9 @@ OK 2 - \\\@<!\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}
OK 0 - ^\(a*\)\1$ OK 0 - ^\(a*\)\1$
OK 1 - ^\(a*\)\1$ OK 1 - ^\(a*\)\1$
OK 2 - ^\(a*\)\1$ OK 2 - ^\(a*\)\1$
OK 0 - ^\(a\{-2,}\)\1\+$
OK 1 - ^\(a\{-2,}\)\1\+$
OK 2 - ^\(a\{-2,}\)\1\+$
OK 0 - <\@<=span. OK 0 - <\@<=span.
OK 1 - <\@<=span. OK 1 - <\@<=span.
OK 2 - <\@<=span. OK 2 - <\@<=span.

View File

@@ -202,6 +202,7 @@ static char *(features[]) = {
static int included_patches[] = { static int included_patches[] = {
// Add new patch number below this line // Add new patch number below this line
289,
288, 288,
//287, //287,
286, 286,