From 5f7e0531c1fe4eb069667e09c0e251e1c6fdee68 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 6 Jul 2019 17:10:12 +0900 Subject: vim-patch:8.1.1611: bufadd() reuses existing buffer without a name Problem: Bufadd() reuses existing buffer without a name. Solution: When the name is empty always create a new buffer. https://github.com/vim/vim/commit/892ae723ab95e429222e930cf41b32809567e58e --- src/nvim/eval.c | 4 +++- src/nvim/testdir/test_functions.vim | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 659f957fd1..15202591f6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7292,7 +7292,9 @@ static buf_T *find_buffer(typval_T *avar) // "bufadd(expr)" function static void f_bufadd(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - rettv->vval.v_number = buflist_add(tv_get_string(&argvars[0]), 0); + char_u *name = tv_get_string(&argvars[0]); + + rettv->vval.v_number = buflist_add(*name == NUL ? NULL : name, 0); } /* diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 64f1c0abd9..615536baef 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1212,6 +1212,20 @@ func Test_bufadd_bufload() call assert_equal(['some', 'text'], getbufline(buf, 1, '$')) call assert_equal(curbuf, bufnr('')) + let buf1 = bufadd('') + let buf2 = bufadd('') + call assert_notequal(0, buf1) + call assert_notequal(0, buf2) + call assert_notequal(buf1, buf2) + call assert_equal(1, bufexists(buf1)) + call assert_equal(1, bufexists(buf2)) + call assert_equal(0, bufloaded(buf1)) + exe 'bwipe ' .. buf1 + call assert_equal(0, bufexists(buf1)) + call assert_equal(1, bufexists(buf2)) + exe 'bwipe ' .. buf2 + call assert_equal(0, bufexists(buf2)) + bwipe someName bwipe otherName call assert_equal(0, bufexists('someName')) -- cgit