Skip to content

Commit

Permalink
updated for version 7.3.1024
Browse files Browse the repository at this point in the history
Problem:    New regexp: End of matching pattern not set correctly. (Cesar
            Romani)
Solution:   Quit the loop after finding the match.  Store nfa_has_zend in the
            program.
  • Loading branch information
brammool committed May 26, 2013
1 parent 3451d66 commit 57a285b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/regexp.h
Expand Up @@ -86,6 +86,7 @@ typedef struct

regprog_T regprog;
nfa_state_T *start;
int has_zend; /* pattern contains \ze */
int nstate;
nfa_state_T state[0]; /* actually longer.. */
} nfa_regprog_T;
Expand Down
12 changes: 9 additions & 3 deletions src/regexp_nfa.c
Expand Up @@ -2651,7 +2651,7 @@ addstate(l, state, m, off, lid, match)
break;

case NFA_MCLOSE + 0:
if (nfa_has_zend == TRUE)
if (nfa_has_zend)
{
addstate(l, state->out, m, off, lid, match);
break;
Expand Down Expand Up @@ -3109,7 +3109,11 @@ nfa_regmatch(start, submatch, m)
fprintf(log_fd, "\n");
#endif
/* Found the left-most longest match, do not look at any other
* states at this position. */
* states at this position. When the list of states is going
* to be empty quit without advancing, so that "reginput" is
* correct. */
if (nextlist->n == 0 && neglist->n == 0)
clen = 0;
goto nextchar;

case NFA_END_INVISIBLE:
Expand Down Expand Up @@ -3783,8 +3787,9 @@ nfa_regexec_both(line, col)
regline = line;
reglnum = 0; /* relative to line */

nstate = prog->nstate;
nfa_has_zend = prog->has_zend;

nstate = prog->nstate;
for (i = 0; i < nstate; ++i)
{
prog->state[i].id = i;
Expand Down Expand Up @@ -3871,6 +3876,7 @@ nfa_regcomp(expr, re_flags)
prog->regflags = regflags;
prog->engine = &nfa_regengine;
prog->nstate = nstate;
prog->has_zend = nfa_has_zend;
#ifdef ENABLE_LOG
nfa_postfix_dump(expr, OK);
nfa_dump(prog);
Expand Down
60 changes: 37 additions & 23 deletions src/testdir/test64.in
Expand Up @@ -15,11 +15,11 @@ STARTTEST
:" etc.
:" When there is no match use only the first two items.
:let tl = []

:"
:""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:"""" Previously written tests """"""""""""""""""""""""""""""""
:""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

:"
:call add(tl, [2, 'ab', 'aab', 'ab'])
:call add(tl, [2, 'b', 'abcdef', 'b'])
:call add(tl, [2, 'bc*', 'abccccdef', 'bcccc'])
Expand Down Expand Up @@ -138,16 +138,16 @@ STARTTEST
:"
:call add(tl, [2, '\v(a*)+', 'aaaa', 'aaaa', ''])
:call add(tl, [2, 'x', 'abcdef'])

:"
:""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:""""" Simple tests """""""""""""""""""""""""""""""""""""""""""
:""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

:"
:" Search single groups
:call add(tl, [2, 'ab', 'aab', 'ab'])
:call add(tl, [2, 'ab', 'baced'])
:call add(tl, [2, 'ab', ' ab ', 'ab'])

:"
:" Search multi-modifiers
:call add(tl, [2, 'x*', 'xcd', 'x'])
:call add(tl, [2, 'x*', 'xxxxxxxxxxxxxxxxsofijiojgf', 'xxxxxxxxxxxxxxxx'])
Expand All @@ -162,7 +162,7 @@ STARTTEST
:call add(tl, [2, 'x\?', 'x sdfoij', 'x'])
:call add(tl, [2, 'x\?', 'abc sfoij', '']) " empty match is good
:call add(tl, [2, 'x\?', 'xxxxxxxxxx c', 'x'])

:"
:call add(tl, [2, 'a\{0,0}', 'abcdfdoij', ''])
:call add(tl, [2, 'a\{0,1}', 'asiubid axxxaaa', 'a']) " same thing as 'a?'
:call add(tl, [2, 'a\{1,0}', 'asiubid axxxaaa', 'a']) " same thing as 'a\{0,1}'
Expand All @@ -182,7 +182,7 @@ STARTTEST
:call add(tl, [2, 'a\{,5}', 'aaaaaaaaaa', 'aaaaa'])
:call add(tl, [2, 'a\{}', 'bbbcddiuhfcd', '']) " same thing as 'a*'
:call add(tl, [2, 'a\{}', 'aaaaioudfh coisf jda', 'aaaa'])

:"
:call add(tl, [2, 'a\{-0,0}', 'abcdfdoij', ''])
:call add(tl, [2, 'a\{-0,1}', 'asiubid axxxaaa', '']) " anti-greedy version of 'a?'
:call add(tl, [2, 'a\{-3,6}', 'aa siofuh'])
Expand All @@ -200,7 +200,7 @@ STARTTEST
:call add(tl, [2, 'a\{-,5}', 'aaaaaaaaaa', ''])
:call add(tl, [0, 'a\{-}', 'bbbcddiuhfcd', '']) " anti-greedy version of 'a*'
:call add(tl, [0, 'a\{-}', 'aaaaioudfh coisf jda', ''])

:"
:" Test groups of characters and submatches
:call add(tl, [2, '\(abc\)*', 'abcabcabc', 'abcabcabc', 'abc'])
:call add(tl, [2, '\(ab\)\+', 'abababaaaaa', 'ababab', 'ab'])
Expand All @@ -213,18 +213,18 @@ STARTTEST
:call add(tl, [2, '\v((ab)|c*)+', 'abcccaba', 'abcccab', '', 'ab'])
:call add(tl, [2, '\v(a(c*)+b)+', 'acbababaaa', 'acbabab', 'ab', ''])
:call add(tl, [2, '\v(a|b*)+', 'aaaa', 'aaaa', ''])

:"
:" Test greedy-ness and lazy-ness
:call add(tl, [2, 'a\{-2,7}','aaaaaaaaaaaaa', 'aa'])
:call add(tl, [2, 'a\{2,7}','aaaaaaaaaaaaaaaaaaaa', 'aaaaaaa'])
:call add(tl, [2, '\vx(.{-,8})yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz','ayxa','xayzxayz'])
:call add(tl, [2, '\vx(.*)yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz', 'ayxayzxayzxa',''])
:call add(tl, [2, '\v(a{1,2}){-2,3}','aaaaaaa','aaaa','aa'])
:call add(tl, [2, '\v(a{-1,3})+','aa','aa','a'])

:"
:" Test Character classes
:call add(tl, [2, '\d\+e\d\d','test 10e23 fd','10e23'])

:"
:" Test collections and character range []
:call add(tl, [2, '\v[a]', 'abcd', 'a'])
:call add(tl, [2, 'a[bcd]', 'abcd', 'ab'])
Expand All @@ -250,8 +250,8 @@ STARTTEST
:call add(tl, [2, 'abc[0-9]*ddd', 'adf abc44482ddd oijs', 'abc44482ddd'])
:call add(tl, [2, '\_[0-9]\+', 'asfi9888u', '9888'])
:call add(tl, [2, '[0-9\n]\+', 'asfi9888u', '9888'])


:"
:"
:"""" Test recognition of some character classes
:call add(tl, [2, '[0-9]', '8', '8'])
:call add(tl, [2, '[^0-9]', '8'])
Expand All @@ -262,7 +262,7 @@ STARTTEST
:call add(tl, [2, '[a-zA-Z]', 'a', 'a'])
:call add(tl, [2, '[A-Z]', 'a'])
:call add(tl, [2, '\C[^A-Z]\+', 'ABCOIJDEOIFNSD jsfoij sa', ' jsfoij sa'])

:"
:"""" Tests for \z features
:call add(tl, [2, 'xx \ze test', 'xx ']) " must match after \ze
:call add(tl, [0, 'abc\zeend', 'oij abcend', 'abc'])
Expand All @@ -271,7 +271,7 @@ STARTTEST
:call add(tl, [0, 'abc \zsmatch\ze abc', 'abc abc abc match abc abc', 'match'])
:call add(tl, [2, '\v(a \zsif .*){2}', 'a if then a if last', 'if last', 'a if last'])
:call add(tl, [2, '\>\zs.', 'aword. ', '.'])

:"
:"""" Tests for \@ features
:call add(tl, [0, 'abc\@=', 'abc', 'ab'])
:call add(tl, [0, 'abc\@=cd', 'abcd', 'abcd'])
Expand All @@ -284,30 +284,30 @@ STARTTEST
:call add(tl, [2, '.*John\&.*Bob', 'here is John, and here is B']) " no match
:call add(tl, [0, '.*John\&.*Bob', 'John is Bobs friend', 'John is Bob'])
:call add(tl, [0, '\v(test1)@=.*yep', 'this is a test1, yep it is', 'test1, yep', 'test1'])

:"
:"""" Combining different tests and features
:call add(tl, [2, '[[:alpha:]]\{-2,6}', '787abcdiuhsasiuhb4', 'ab'])
:call add(tl, [2, '', 'abcd', ''])
:call add(tl, [2, '\v(())', 'any possible text', ''])
:call add(tl, [2, '\v%(ab(xyz)c)', ' abxyzc ', 'abxyzc', 'xyz'])
:call add(tl, [2, '\v(test|)empty', 'tesempty', 'empty', ''])
:call add(tl, [2, '\v(a|aa)(a|aa)', 'aaa', 'aa', 'a', 'a'])

:"
:"""" \%u and friends
:call add(tl, [2, '\%d32', 'yes no', ' '])
:call add(tl, [2, '\%o40', 'yes no', ' '])
:call add(tl, [2, '\%x20', 'yes no', ' '])
:call add(tl, [2, '\%u0020', 'yes no', ' '])
:call add(tl, [2, '\%U00000020', 'yes no', ' '])

:"
:"""" Alternatives, must use first longest match
:call add(tl, [2, 'goo\|go', 'google', 'goo'])
:call add(tl, [2, '\<goo\|\<go', 'google', 'goo'])
:call add(tl, [2, '\<goo\|go', 'google', 'goo'])


:"
:"
:"""" Run the tests

:"
:"
:for t in tl
: let re = t[0]
Expand Down Expand Up @@ -347,7 +347,7 @@ STARTTEST
: endfor
:endfor
:unlet t tl e l

:"
:" Check that \_[0-9] matching EOL does not break a following \>
:" This only works on a buffer line, not with expression evaluation
/^Find this
Expand All @@ -359,11 +359,25 @@ y$Gop:"
/^Find this
/\%#=2\<\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\>
y$Gop:"

:"
:" Check that using a pattern on two lines doesn't get messed up by using
:" matchstr() with \ze in between.
:set re=0
/^Substitute here
:.+1,.+2s/""/\='"'.matchstr(getline("."), '\d\+\ze<').'"'
/^Substitute here
:.+1,.+2yank
Gop:"
:"
:"
:/\%#=1^Results/,$wq! test.out
ENDTEST

Find this:
localnet/192.168.0.1

Substitute here:
<T="">Ta 5</Title>
<T="">Ac 7</Title>

Results of test64:
3 changes: 3 additions & 0 deletions src/testdir/test64.ok
Expand Up @@ -693,3 +693,6 @@ OK 2 - \<goo\|go
192.168.0.1
192.168.0.1
192.168.0.1

<T="5">Ta 5</Title>
<T="7">Ac 7</Title>
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -728,6 +728,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1024,
/**/
1023,
/**/
Expand Down

0 comments on commit 57a285b

Please sign in to comment.