]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.158 v7.4.158
authorBram Moolenaar <Bram@vim.org>
Thu, 23 Jan 2014 19:09:34 +0000 (20:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 23 Jan 2014 19:09:34 +0000 (20:09 +0100)
Problem:    Pattern containing \zs is not handled correctly by substitute().
Solution:   Change how an empty match is skipped. (Yukihiro Nakadaira)

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

index 7b7302f74ab9dc3f26baaca79643e96110c3a3f8..3786adfdfb97a093d02441c972fad195ce761b0a 100644 (file)
@@ -24365,7 +24365,7 @@ do_string_sub(str, pat, sub, flags)
     garray_T   ga;
     char_u     *ret;
     char_u     *save_cpo;
-    int                zero_width;
+    char_u     *zero_width = NULL;
 
     /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
     save_cpo = p_cpo;
@@ -24382,6 +24382,19 @@ do_string_sub(str, pat, sub, flags)
        tail = str;
        while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
        {
+           /* Skip empty match except for first match. */
+           if (regmatch.startp[0] == regmatch.endp[0])
+           {
+               if (zero_width == regmatch.startp[0])
+               {
+                   /* avoid getting stuck on a match with an empty string */
+                   *((char_u *)ga.ga_data + ga.ga_len) = *tail++;
+                   ++ga.ga_len;
+                   continue;
+               }
+               zero_width = regmatch.startp[0];
+           }
+
            /*
             * Get some space for a temporary buffer to do the substitution
             * into.  It will contain:
@@ -24404,17 +24417,9 @@ 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;
-           zero_width = (tail == regmatch.endp[0]
-                                   || regmatch.startp[0] == regmatch.endp[0]);
            tail = regmatch.endp[0];
            if (*tail == NUL)
                break;
-           if (zero_width)
-           {
-               /* avoid getting stuck on a match with an empty string */
-               *((char_u *)ga.ga_data + ga.ga_len) = *tail++;
-               ++ga.ga_len;
-           }
            if (!do_all)
                break;
        }
index 5491a90092978c3bef93909984720eddcd8e734b..c62fdc02b273edef561514178b575c4e2b6da2ef 100644 (file)
@@ -175,6 +175,23 @@ ENDTEST
 
 TEST_10:
 
+STARTTEST
+:set magic&
+:set cpo&
+:$put =\"\n\nTEST_10:\"
+:let y = substitute('123', '\zs', 'a', 'g')             | $put =y
+:let y = substitute('123', '\zs.', 'a', 'g')            | $put =y
+:let y = substitute('123', '.\zs', 'a', 'g')            | $put =y
+:let y = substitute('123', '\ze', 'a', 'g')             | $put =y
+:let y = substitute('123', '\ze.', 'a', 'g')            | $put =y
+:let y = substitute('123', '.\ze', 'a', 'g')            | $put =y
+:let y = substitute('123', '1\|\ze', 'a', 'g')          | $put =y
+:let y = substitute('123', '1\zs\|[23]', 'a', 'g')      | $put =y
+/^TEST_11
+ENDTEST
+
+TEST_11:
+
 STARTTEST
 :/^Results/,$wq! test.out
 ENDTEST
index 562bbf249c8e14fe5c1b509b12013f52d810d71f..2b79d377a73f5fb652f2bf78df2263b5112eb69d 100644 (file)
@@ -115,3 +115,14 @@ N,,NZ
 
 TEST_9:
 XXx
+
+
+TEST_10:
+a1a2a3a
+aaa
+1a2a3a
+a1a2a3a
+a1a2a3
+aaa
+aa2a3a
+1aaa
index b80bacdbabe127b5c5dd9c75008b90c9b2951b90..00e1ae6b101316cd39ae23dcf1d5ba5ae22e479c 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    158,
 /**/
     157,
 /**/