From 03b3ff861082ff09f2903565d928187489225306 Mon Sep 17 00:00:00 2001 From: jing Date: Sat, 1 May 2021 10:44:21 +0800 Subject: vim-patch:8.2.2340: win_execute() unexpectedly returns number zero when failing Problem: win_execute() unexpectedly returns number zero when failing. Solution: Return an empty string. (closes vim/vim#7665) https://github.com/vim/vim/commit/37487e16da7877129edee8d11b9b7f5c8df312c6 --- src/nvim/eval/funcs.c | 3 +++ src/nvim/testdir/test_execute_func.vim | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 2a046efc0b..04e6a73f37 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2045,6 +2045,9 @@ static void f_win_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) win_T *wp = win_id2wp_tp(argvars, &tp); win_T *save_curwin; tabpage_T *save_curtab; + // Return an empty string if something fails. + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; if (wp != NULL && tp != NULL) { pos_T curpos = wp->w_cursor; diff --git a/src/nvim/testdir/test_execute_func.vim b/src/nvim/testdir/test_execute_func.vim index 51df61d762..15ba894dbe 100644 --- a/src/nvim/testdir/test_execute_func.vim +++ b/src/nvim/testdir/test_execute_func.vim @@ -93,6 +93,8 @@ func Test_win_execute() call win_gotoid(thiswin) let line = win_execute(otherwin, 'echo getline(1)') call assert_match('the new window', line) + let line = win_execute(134343, 'echo getline(1)') + call assert_equal('', line) if has('textprop') let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) -- cgit