summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-09-29 21:11:05 +0200
committerBram Moolenaar <Bram@vim.org>2013-09-29 21:11:05 +0200
commitceb84af027ac782f0b9de0e66f321258358e391a (patch)
tree22f08b3f3763b3f20dbef2b2faef8082e9dcc964
parent8962fda1dacf374d78bd02ca487800c2519c57b2 (diff)
downloadvim-ceb84af027ac782f0b9de0e66f321258358e391a.zip
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)
-rw-r--r--src/eval.c18
-rw-r--r--src/testdir/test80.in2
-rw-r--r--src/testdir/test80.ok2
-rw-r--r--src/version.c2
4 files changed, 14 insertions, 10 deletions
diff --git a/src/eval.c b/src/eval.c
index 03e3735ce..68f80fc7d 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -24301,6 +24301,7 @@ do_string_sub(str, pat, sub, flags)
garray_T ga;
char_u *ret;
char_u *save_cpo;
+ int zero_width;
/* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
save_cpo = p_cpo;
@@ -24339,20 +24340,17 @@ do_string_sub(str, pat, sub, flags)
(void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
+ ga.ga_len + i, TRUE, TRUE, FALSE);
ga.ga_len += i + sublen - 1;
- /* avoid getting stuck on a match with an empty string */
- if (tail == regmatch.endp[0])
+ zero_width = (tail == regmatch.endp[0]
+ || regmatch.startp[0] == regmatch.endp[0]);
+ tail = regmatch.endp[0];
+ if (*tail == NUL)
+ break;
+ if (zero_width)
{
- if (*tail == NUL)
- break;
+ /* avoid getting stuck on a match with an empty string */
*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
++ga.ga_len;
}
- else
- {
- tail = regmatch.endp[0];
- if (*tail == NUL)
- break;
- }
if (!do_all)
break;
}
diff --git a/src/testdir/test80.in b/src/testdir/test80.in
index 7f6ecfccb..5491a9009 100644
--- a/src/testdir/test80.in
+++ b/src/testdir/test80.in
@@ -142,6 +142,8 @@ STARTTEST
:$put =\"\n\nTEST_7:\"
:$put =substitute('A A', 'A.', '\=submatch(0)', '')
:$put =substitute(\"B\nB\", 'B.', '\=submatch(0)', '')
+:$put =substitute('-bb', '\zeb', 'a', 'g')
+:$put =substitute('-bb', '\ze', 'c', 'g')
/^TEST_8
ENDTEST
diff --git a/src/testdir/test80.ok b/src/testdir/test80.ok
index 45b1d1d0f..562bbf249 100644
--- a/src/testdir/test80.ok
+++ b/src/testdir/test80.ok
@@ -103,6 +103,8 @@ TEST_7:
A A
B
B
+-abab
+c-cbcbc
TEST_8:
diff --git a/src/version.c b/src/version.c
index 52ad91e1d..63882ee78 100644
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 45,
+/**/
44,
/**/
43,