]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1039: cannot put NUL byte on clipboard v8.2.1039
authorBram Moolenaar <Bram@vim.org>
Mon, 22 Jun 2020 18:30:27 +0000 (20:30 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Jun 2020 18:30:27 +0000 (20:30 +0200)
Problem:    Cannot put NUL byte on clipboard.
Solution:   Use the text length. (Christian Brabandt, closes #6312,
            closes #6149)

src/testdir/test_registers.vim
src/version.c
src/winclip.c

index c9135628c06fc3a7f2c663c0eb8404490be7d9f4..d92ad977f1fe6084018abe5b873772dcfc31e641 100644 (file)
@@ -641,4 +641,22 @@ func Test_execute_reg_as_ex_cmd()
   call assert_equal(repeat('abcdefghijklmnopqrstuvwxyz', 312), str)
 endfunc
 
+" Test for clipboard registers with ASCII NUL
+func Test_clipboard_nul()
+  CheckFeature clipboard_working
+  new
+
+  " Test for putting ASCII NUL into the clipboard
+  set clipboard=unnamed
+  call append(0, "\ntest")
+  normal ggyyp
+  call assert_equal("^@test^@", strtrans(getreg('*')))
+  call assert_equal(getline(1), getline(2))
+  let b = split(execute(":reg *"), "\n")
+  call assert_match('"\*\s*\^@test\^J',b[1])
+
+  set clipboard&vim
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index b383830c95ff32b7ac7aedc1d4e960f9f7eb4597..d6ed2cd972002da06b0aa2191dcfd450771ea189 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1039,
 /**/
     1038,
 /**/
index 767bf1c71e0b41a3d8f3c7b355429b3c09054821..db88e6787dfd3b587a489c8e8f76437a692bfc73 100644 (file)
@@ -422,7 +422,7 @@ clip_mch_request_selection(Clipboard_T *cbd)
        }
     }
 
-    if (str != NULL && *str != NUL)
+    if (str != NULL && metadata.txtlen != 0)
     {
        char_u *temp_clipboard;
 
@@ -543,7 +543,7 @@ clip_mch_set_selection(Clipboard_T *cbd)
 
        if (lpszMem)
        {
-           vim_strncpy((char_u *)lpszMem, str, metadata.txtlen);
+           mch_memmove((char_u *)lpszMem, str, metadata.txtlen);
            GlobalUnlock(hMem);
        }
     }