]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.045 v7.4.045
authorBram Moolenaar <Bram@vim.org>
Sun, 29 Sep 2013 19:11:05 +0000 (21:11 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 29 Sep 2013 19:11:05 +0000 (21:11 +0200)
Problem:    substitute() does not work properly when the pattern starts with
            "\ze".
Solution:   Detect an empty match. (Christian Brabandt)

src/eval.c
src/testdir/test80.in
src/testdir/test80.ok
src/version.c

index 03e3735ce9f412753176adb3e6ed140eb056838c..68f80fc7dbac92fdfc3c12cb76bd1ed35d65f5a1 100644 (file)
@@ -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;
        }
index 7f6ecfccb5da3941fbd7a91f1013bd9df48b698f..5491a90092978c3bef93909984720eddcd8e734b 100644 (file)
@@ -142,6 +142,8 @@ STARTTEST
 :$put =\"\n\nTEST_7:\"
 :$put =substitute('A\16\rA', '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
 
index 45b1d1d0f102e1a5b58177f94dcd65e46d509cff..562bbf249c8e14fe5c1b509b12013f52d810d71f 100644 (file)
@@ -103,6 +103,8 @@ TEST_7:
 A\rA
 B
 B
+-abab
+c-cbcbc
 
 
 TEST_8:
index 52ad91e1d6fdbdd2b2622089fd01e19c82c6951a..63882ee7872f21a858719b7fdc674b4d437b3e8a 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    45,
 /**/
     44,
 /**/