Skip to content

Commit a21c226

Browse files
committed
updated for version 7.4.045
Problem: substitute() does not work properly when the pattern starts with "\ze". Solution: Detect an empty match. (Christian Brabandt)
1 parent b8eb72c commit a21c226

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/eval.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24301,6 +24301,7 @@ do_string_sub(str, pat, sub, flags)
2430124301
garray_T ga;
2430224302
char_u *ret;
2430324303
char_u *save_cpo;
24304+
int zero_width;
2430424305

2430524306
/* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
2430624307
save_cpo = p_cpo;
@@ -24339,20 +24340,17 @@ do_string_sub(str, pat, sub, flags)
2433924340
(void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
2434024341
+ ga.ga_len + i, TRUE, TRUE, FALSE);
2434124342
ga.ga_len += i + sublen - 1;
24342-
/* avoid getting stuck on a match with an empty string */
24343-
if (tail == regmatch.endp[0])
24343+
zero_width = (tail == regmatch.endp[0]
24344+
|| regmatch.startp[0] == regmatch.endp[0]);
24345+
tail = regmatch.endp[0];
24346+
if (*tail == NUL)
24347+
break;
24348+
if (zero_width)
2434424349
{
24345-
if (*tail == NUL)
24346-
break;
24350+
/* avoid getting stuck on a match with an empty string */
2434724351
*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
2434824352
++ga.ga_len;
2434924353
}
24350-
else
24351-
{
24352-
tail = regmatch.endp[0];
24353-
if (*tail == NUL)
24354-
break;
24355-
}
2435624354
if (!do_all)
2435724355
break;
2435824356
}

src/testdir/test80.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ STARTTEST
142142
:$put =\"\n\nTEST_7:\"
143143
:$put =substitute('AA', 'A.', '\=submatch(0)', '')
144144
:$put =substitute(\"B\nB\", 'B.', '\=submatch(0)', '')
145+
:$put =substitute('-bb', '\zeb', 'a', 'g')
146+
:$put =substitute('-bb', '\ze', 'c', 'g')
145147
/^TEST_8
146148
ENDTEST
147149

src/testdir/test80.ok

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ TEST_7:
103103
AA
104104
B
105105
B
106+
-abab
107+
c-cbcbc
106108

107109

108110
TEST_8:

src/version.c

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

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
45,
741743
/**/
742744
44,
743745
/**/

0 commit comments

Comments
 (0)