]> granicus.if.org Git - vim/commitdiff
patch 9.0.0261: bufload() reads a file even if the name is not a file name v9.0.0261
authorBram Moolenaar <Bram@vim.org>
Thu, 25 Aug 2022 11:45:21 +0000 (12:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 25 Aug 2022 11:45:21 +0000 (12:45 +0100)
Problem:    bufload() reads a file even if the name is not a file name. (Cyker
            Way)
Solution:   Do not read the file when the buffer name is not a file name.
            (closes #10975)

runtime/doc/builtin.txt
src/buffer.c
src/testdir/test_functions.vim
src/version.c

index c1dea37ad0eba79865a9eb956f97973ee11593c1..7df5e9f0995212bf11dfb3c05afb2bc5358ac55f 100644 (file)
@@ -1179,7 +1179,8 @@ browsedir({title}, {initdir})
                browsing is not possible, an empty string is returned.
 
 bufadd({name})                                         *bufadd()*
-               Add a buffer to the buffer list with String {name}.
+               Add a buffer to the buffer list with name {name} (must be a
+               String).
                If a buffer for file {name} already exists, return that buffer
                number.  Otherwise return the buffer number of the newly
                created buffer.  When {name} is an empty string then a new
@@ -1232,7 +1233,8 @@ bufload({buf})                                            *bufload()*
                Ensure the buffer {buf} is loaded.  When the buffer name
                refers to an existing file then the file is read.  Otherwise
                the buffer will be empty.  If the buffer was already loaded
-               then there is no change.
+               then there is no change.  If the buffer is not related to a
+               file the no file is read (e.g., when 'buftype' is "nofile").
                If there is an existing swap file for the file of the buffer,
                there will be no dialog, the buffer will be loaded anyway.
                The {buf} argument is used like with |bufexists()|.
index fba6c218fd6edcda5d52d5601fb8f5a976689f8c..cfed0f327cd58c8d5a2b4a690a3b8b691b340c70 100644 (file)
@@ -220,7 +220,10 @@ open_buffer(
     // mark cursor position as being invalid
     curwin->w_valid = 0;
 
+    // Read the file if there is one.
     if (curbuf->b_ffname != NULL
+           && !bt_quickfix(curbuf)
+           && !bt_nofilename(curbuf)
 #ifdef FEAT_NETBEANS_INTG
            && netbeansReadFile
 #endif
index 38cd7930aff3e9f1f090746433a379d2f36ed43e..68970407cefa72f1ffd2d12b8fdcbad4be28082f 100644 (file)
@@ -2368,6 +2368,13 @@ func Test_bufadd_bufload()
   exe 'bwipe ' .. buf2
   call assert_equal(0, bufexists(buf2))
 
+  " when 'buftype' is "nofile" then bufload() does not read the file
+  bwipe! XotherName
+  let buf = bufadd('XotherName')
+  call setbufvar(buf, '&bt', 'nofile')
+  call bufload(buf)
+  call assert_equal([''], getbufline(buf, 1, '$'))
+
   bwipe someName
   bwipe XotherName
   call assert_equal(0, bufexists('someName'))
index 02c20f03f6026b31f65784a8999d1e94cf5c8bce..867d971746d3c717f288e91ef6703ff60ea7bf16 100644 (file)
@@ -731,6 +731,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    261,
 /**/
     260,
 /**/