Mercurial > vim
changeset 5964:238f5027830c v7.4.323
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)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 12 Jun 2014 18:39:22 +0200 |
parents | c23596b8e34f |
children | fdc26d6de8a2 |
files | src/eval.c src/testdir/test69.in src/testdir/test69.ok src/version.c |
diffstat | 4 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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];
--- a/src/testdir/test69.in +++ b/src/testdir/test69.in @@ -180,6 +180,13 @@ 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 ENDTEST