substitute() with zero width pattern breaks multi-byte character.
Steps to reproduce:
$ vim -u NONE
:set encoding=utf-8
:echo substitute("\u00e1", '\zs', 'x', 'g')
x<c3>x<a1>x
Please check the following patch.
diff -r bed71c37618c src/eval.c
--- a/src/eval.c Thu May 29 14:36:29 2014 +0200
+++ b/src/eval.c Wed Jun 04 20:44:48 2014 +0900
@@ -24848,8 +24848,11 @@
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 -r bed71c37618c src/testdir/test69.in
--- a/src/testdir/test69.in Thu May 29 14:36:29 2014 +0200
+++ b/src/testdir/test69.in Wed Jun 04 20:44:48 2014 +0900
@@ -180,6 +180,13 @@
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
diff -r bed71c37618c src/testdir/test69.ok
--- a/src/testdir/test69.ok Thu May 29 14:36:29 2014 +0200
+++ b/src/testdir/test69.ok Wed Jun 04 20:44:48 2014 +0900
@@ -160,3 +160,7 @@
[0, 1, 3, 4, -1]
[0, 1, 2, 4, 5, -1]
+
+substitute
+a1a2a3a
+
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.