summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-06-11 14:47:40 +0200
committerBram Moolenaar <Bram@vim.org>2016-06-11 14:47:40 +0200
commit012270936c3c7df3bba45ad2b48938c23a2fd43a (patch)
tree49516acf5e48807dc57ee1b62ce5d5e596209e8e /src
parentb8aefa46adf5e825118716e142fab7ef32076475 (diff)
downloadvim-git-012270936c3c7df3bba45ad2b48938c23a2fd43a.tar.gz
patch 7.4.1917v7.4.1917
Problem: History lines read from viminfo in different encoding than when writing are not converted. Solution: Convert the history lines.
Diffstat (limited to 'src')
-rw-r--r--src/ex_cmds.c30
-rw-r--r--src/testdir/test_viminfo.vim22
-rw-r--r--src/version.c2
3 files changed, 52 insertions, 2 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 5e56489a3..37e8e4c33 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2543,6 +2543,10 @@ barline_parse(vir_T *virp, char_u *text, bval_T *values)
int count = 0;
int i;
int allocated = FALSE;
+#ifdef FEAT_MBYTE
+ char_u *sconv;
+ int converted;
+#endif
while (*p == ',')
{
@@ -2560,7 +2564,8 @@ barline_parse(vir_T *virp, char_u *text, bval_T *values)
if (!allocated)
{
for (i = 0; i < count; ++i)
- if (values[i].bv_type == BVAL_STRING)
+ if (values[i].bv_type == BVAL_STRING
+ && !values[i].bv_allocated)
{
values[i].bv_string = vim_strnsave(
values[i].bv_string, values[i].bv_len);
@@ -2654,12 +2659,33 @@ barline_parse(vir_T *virp, char_u *text, bval_T *values)
}
s[len] = NUL;
+#ifdef FEAT_MBYTE
+ converted = FALSE;
+ if (virp->vir_conv.vc_type != CONV_NONE && *s != NUL)
+ {
+ sconv = string_convert(&virp->vir_conv, s, NULL);
+ if (sconv != NULL)
+ {
+ if (s == buf)
+ vim_free(s);
+ s = sconv;
+ buf = s;
+ converted = TRUE;
+ }
+ }
+#endif
+ /* Need to copy in allocated memory if the string wasn't allocated
+ * above and we did allocate before, thus vir_line may change. */
if (s != buf && allocated)
s = vim_strsave(s);
values[count].bv_string = s;
values[count].bv_type = BVAL_STRING;
values[count].bv_len = len;
- values[count].bv_allocated = allocated;
+ values[count].bv_allocated = allocated
+#ifdef FEAT_MBYTE
+ || converted
+#endif
+ ;
++count;
if (nextp != NULL)
{
diff --git a/src/testdir/test_viminfo.vim b/src/testdir/test_viminfo.vim
index 279b1c3d1..1fefba1b6 100644
--- a/src/testdir/test_viminfo.vim
+++ b/src/testdir/test_viminfo.vim
@@ -179,3 +179,25 @@ func Test_cmdline_history_order()
call delete('Xviminfo')
endfunc
+
+func Test_viminfo_encoding()
+ if !has('multi_byte')
+ return
+ endif
+ set enc=latin1
+ call histdel(':')
+ call histadd(':', "echo '\xe9'")
+ wviminfo Xviminfo
+
+ set fencs=utf-8,latin1
+ set enc=utf-8
+ sp Xviminfo
+ call assert_equal('latin1', &fenc)
+ close
+
+ call histdel(':')
+ rviminfo Xviminfo
+ call assert_equal("echo 'é'", histget(':', -1))
+
+ call delete('Xviminfo')
+endfunc
diff --git a/src/version.c b/src/version.c
index dfeee7256..684ec7646 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1917,
+/**/
1916,
/**/
1915,