Skip to content

Commit c057922

Browse files
committed
updated for version 7.3.1243
Problem: New regexp engine: back references in look-behind match don't work. (Lech Lorens) Solution: Copy the submatches before a recursive match.
1 parent 0195cfb commit c057922

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/regexp_nfa.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ static void nfa_dump __ARGS((nfa_regprog_T *prog));
290290
#endif
291291
static int *re2post __ARGS((void));
292292
static nfa_state_T *alloc_state __ARGS((int c, nfa_state_T *out, nfa_state_T *out1));
293+
static void st_error __ARGS((int *postfix, int *end, int *p));
294+
static int nfa_max_width __ARGS((nfa_state_T *startstate, int depth));
293295
static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size));
294296
static void nfa_postprocess __ARGS((nfa_regprog_T *prog));
295297
static int check_char_class __ARGS((int class, int c));
296-
static void st_error __ARGS((int *postfix, int *end, int *p));
297298
static void nfa_save_listids __ARGS((nfa_regprog_T *prog, int *list));
298299
static void nfa_restore_listids __ARGS((nfa_regprog_T *prog, int *list));
299300
static int nfa_re_num_cmp __ARGS((long_u val, int op, long_u pos));
@@ -3469,6 +3470,7 @@ typedef struct
34693470
#ifdef ENABLE_LOG
34703471
static void log_subsexpr __ARGS((regsubs_T *subs));
34713472
static void log_subexpr __ARGS((regsub_T *sub));
3473+
static char *pim_info __ARGS((nfa_pim_T *pim));
34723474

34733475
static void
34743476
log_subsexpr(subs)
@@ -3508,7 +3510,8 @@ log_subexpr(sub)
35083510
}
35093511

35103512
static char *
3511-
pim_info(nfa_pim_T *pim)
3513+
pim_info(pim)
3514+
nfa_pim_T *pim;
35123515
{
35133516
static char buf[30];
35143517

@@ -3532,6 +3535,7 @@ static void clear_sub __ARGS((regsub_T *sub));
35323535
static void copy_sub __ARGS((regsub_T *to, regsub_T *from));
35333536
static void copy_sub_off __ARGS((regsub_T *to, regsub_T *from));
35343537
static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2));
3538+
static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
35353539
static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
35363540
static int state_in_list __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
35373541
static void addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int off));
@@ -4319,8 +4323,6 @@ check_char_class(class, c)
43194323
return FAIL;
43204324
}
43214325

4322-
static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
4323-
43244326
/*
43254327
* Check for a match with subexpression "subidx".
43264328
* Return TRUE if it matches.
@@ -5195,6 +5197,10 @@ nfa_regmatch(prog, start, submatch, m)
51955197
|| t->state->c == NFA_START_INVISIBLE_BEFORE_FIRST
51965198
|| t->state->c == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)
51975199
{
5200+
/* Copy submatch info for the recursive call, so that
5201+
* \1 can be matched. */
5202+
copy_sub_off(&m->norm, &t->subs.norm);
5203+
51985204
/*
51995205
* First try matching the invisible match, then what
52005206
* follows.

src/testdir/test64.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ STARTTEST
380380
:call add(tl, [2, '\(a\)\(b\)\(c\)\(dd\)\(e\)\(f\)\(g\)\(h\)\(i\)\1\2\3\4\5\6\7\8\9', 'xabcddefghiabcddefghix', 'abcddefghiabcddefghi', 'a', 'b', 'c', 'dd', 'e', 'f', 'g', 'h', 'i'])
381381
:call add(tl, [2, '\(\d*\)a \1b', ' a b ', 'a b', ''])
382382
:call add(tl, [2, '^.\(.\).\_..\1.', "aaa\naaa\nb", "aaa\naaa", 'a'])
383+
:call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<!$', 'foo.bat/foo.com', 'foo.bat/foo.com', 'bat'])
384+
:call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<!$', 'foo.bat/foo.bat'])
385+
:call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<=$', 'foo.bat/foo.bat', 'foo.bat/foo.bat', 'bat', 'bat'])
383386
:"
384387
:"""" Look-behind with limit
385388
:call add(tl, [2, '<\@<=span.', 'xxspanxx<spanyyy', 'spany'])

src/testdir/test64.ok

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,15 @@ OK 2 - \(\d*\)a \1b
866866
OK 0 - ^.\(.\).\_..\1.
867867
OK 1 - ^.\(.\).\_..\1.
868868
OK 2 - ^.\(.\).\_..\1.
869+
OK 0 - ^.*\.\(.*\)/.\+\(\1\)\@<!$
870+
OK 1 - ^.*\.\(.*\)/.\+\(\1\)\@<!$
871+
OK 2 - ^.*\.\(.*\)/.\+\(\1\)\@<!$
872+
OK 0 - ^.*\.\(.*\)/.\+\(\1\)\@<!$
873+
OK 1 - ^.*\.\(.*\)/.\+\(\1\)\@<!$
874+
OK 2 - ^.*\.\(.*\)/.\+\(\1\)\@<!$
875+
OK 0 - ^.*\.\(.*\)/.\+\(\1\)\@<=$
876+
OK 1 - ^.*\.\(.*\)/.\+\(\1\)\@<=$
877+
OK 2 - ^.*\.\(.*\)/.\+\(\1\)\@<=$
869878
OK 0 - <\@<=span.
870879
OK 1 - <\@<=span.
871880
OK 2 - <\@<=span.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ static char *(features[]) =
728728

729729
static int included_patches[] =
730730
{ /* Add new patch number below this line */
731+
/**/
732+
1243,
731733
/**/
732734
1242,
733735
/**/

0 commit comments

Comments
 (0)