]> granicus.if.org Git - vim/commitdiff
patch 8.1.0118: duplicate error message for put command v8.1.0118
authorBram Moolenaar <Bram@vim.org>
Wed, 27 Jun 2018 18:49:44 +0000 (20:49 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 27 Jun 2018 18:49:44 +0000 (20:49 +0200)
Problem:    Duplicate error message for put command.
Solution:   Check return value of u_save(). (Jason Franklin)

src/ops.c
src/testdir/test_messages.vim
src/testdir/test_put.vim
src/version.c

index 2dbc74889d8696f86a38a4bf53e8382e93396884..73f73d2f92d600da35650919364797068df0486c 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -3551,9 +3551,10 @@ do_put(
            return;
     }
 
-    /* Autocommands may be executed when saving lines for undo, which may make
-     * y_array invalid.  Start undo now to avoid that. */
-    u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1);
+    /* Autocommands may be executed when saving lines for undo.  This might
+     * make "y_array" invalid, so we start undo now to avoid that. */
+    if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL)
+       goto end;
 
     if (insert_string != NULL)
     {
index 384d2aa94f4fb1092e606d30d71ea5551d022f11..a85799e2635de4f92077f309b0dabfa3cc5d62e5 100644 (file)
@@ -39,7 +39,7 @@ function Test_messages()
   endtry
 endfunction
 
-" Patch 7.4.1696 defined the "clearmode()" command for clearing the mode
+" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
 " indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked.  Message
 " output could then be disturbed when 'cmdheight' was greater than one.
 " This test ensures that the bugfix for this issue remains in place.
index 0a23a43919026d65e742ceed0593136fad4eedd6..e425c44f9f766b207e1451431dbab2a9c6d9b636 100644 (file)
@@ -1,3 +1,4 @@
+" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
 
 func Test_put_block()
   if !has('multi_byte')
@@ -58,3 +59,48 @@ func Test_put_expr()
   call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1,'$'))
   bw!
 endfunc
+
+func Test_put_fails_when_nomodifiable()
+  new
+  set nomodifiable
+
+  normal! yy
+  call assert_fails(':put', 'E21')
+  call assert_fails(':put!', 'E21')
+  call assert_fails(':normal! p', 'E21')
+  call assert_fails(':normal! gp', 'E21')
+  call assert_fails(':normal! P', 'E21')
+  call assert_fails(':normal! gP', 'E21')
+
+  if has('mouse')
+    set mouse=n
+    call assert_fails('execute "normal! \<MiddleMouse>"', 'E21')
+    set mouse&
+  endif
+
+  bwipeout!
+endfunc
+
+" A bug was discovered where the Normal mode put commands (e.g., "p") would
+" output duplicate error messages when invoked in a non-modifiable buffer.
+func Test_put_p_errmsg_nodup()
+  new
+  set nomodifiable
+
+  normal! yy
+
+  func Capture_p_error()
+    redir => s:p_err
+    normal! p
+    redir END
+  endfunc
+
+  silent! call Capture_p_error()
+
+  " Error message output within a function should be three lines (the function
+  " name, the line number, and the error message).
+  call assert_equal(3, count(s:p_err, "\n"))
+
+  delfunction Capture_p_error
+  bwipeout!
+endfunc
index 88a654185488b1c5f1eba6a8f8c52dd01397b4b3..ff3806af86a602c2dd6e9f97b16f35f035943055 100644 (file)
@@ -789,6 +789,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    118,
 /**/
     117,
 /**/