From 8e7048ca4b699bbdb8452c0f8c642bfd66cc7bf4 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 12 Jun 2014 18:39:22 +0200 Subject: updated for version 7.4.323 Problem: Substitute() with zero width pattern breaks multi-byte character. Solution: Take multi-byte character size into account. (Yukihiro Nakadaira) --- src/eval.c | 7 +++++-- src/testdir/test69.in | 7 +++++++ src/testdir/test69.ok | 4 ++++ src/version.c | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/eval.c b/src/eval.c index 51ec0b8b9..728b7d1e2 100644 --- a/src/eval.c +++ b/src/eval.c @@ -24848,8 +24848,11 @@ do_string_sub(str, pat, sub, flags) 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; + i = MB_PTR2LEN(tail); + mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, + (size_t)i); + ga.ga_len += i; + tail += i; continue; } zero_width = regmatch.startp[0]; diff --git a/src/testdir/test69.in b/src/testdir/test69.in index 75317b495..2510c122b 100644 --- a/src/testdir/test69.in +++ b/src/testdir/test69.in @@ -179,6 +179,13 @@ ENDTEST byteidx byteidxcomp +STARTTEST +/^substitute +:let y = substitute('123', '\zs', 'a', 'g') | put =y +ENDTEST + +substitute + STARTTEST :g/^STARTTEST/.,/^ENDTEST/d :1;/^Results/,$wq! test.out diff --git a/src/testdir/test69.ok b/src/testdir/test69.ok index 41cd9d02c..af8befb0c 100644 --- a/src/testdir/test69.ok +++ b/src/testdir/test69.ok @@ -160,3 +160,7 @@ byteidxcomp [0, 1, 3, 4, -1] [0, 1, 2, 4, 5, -1] + +substitute +a1a2a3a + diff --git a/src/version.c b/src/version.c index 5556ed7ee..93046ddd5 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 323, /**/ 322, /**/ -- cgit v1.2.1