]> granicus.if.org Git - vim/commitdiff
patch 8.2.0507: getbufvar() may get the wrong dictionary v8.2.0507
authorBram Moolenaar <Bram@vim.org>
Fri, 3 Apr 2020 16:43:35 +0000 (18:43 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 3 Apr 2020 16:43:35 +0000 (18:43 +0200)
Problem:    Getbufvar() may get the wrong dictionary. (David le Blanc)
Solution:   Check for empty name. (closes #5878)

src/evalvars.c
src/testdir/test_functions.vim
src/version.c

index 7e408864ff4dc082f3df53001dcccb86d0cc4803..c4bc957fcd384b5896292ac2c5f41d8e356e0fb3 100644 (file)
@@ -2382,6 +2382,7 @@ find_var(char_u *name, hashtab_T **htp, int no_autoload)
 
 /*
  * Find variable "varname" in hashtab "ht" with name "htname".
+ * When "varname" is empty returns curwin/curtab/etc vars dictionary.
  * Returns NULL if not found.
  */
     dictitem_T *
@@ -3503,8 +3504,12 @@ f_getbufvar(typval_T *argvars, typval_T *rettv)
        else
        {
            // Look up the variable.
-           // Let getbufvar({nr}, "") return the "b:" dictionary.
-           v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', varname, FALSE);
+           if (*varname == NUL)
+               // Let getbufvar({nr}, "") return the "b:" dictionary.
+               v = &buf->b_bufvar;
+           else
+               v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b',
+                                                              varname, FALSE);
            if (v != NULL)
            {
                copy_tv(&v->di_tv, rettv);
index 7462da856d42d11c6d52a65b7413112131f8b100..9260fb0e5ededf0da6cbdb34012e7c31d299ac36 100644 (file)
@@ -841,6 +841,16 @@ func Test_getbufvar()
   call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc'))
   close
 
+  " Get the b: dict.
+  let b:testvar = 'one'
+  new
+  let b:testvar = 'two'
+  let thebuf = bufnr()
+  wincmd w
+  call assert_equal('two', getbufvar(thebuf, 'testvar'))
+  call assert_equal('two', getbufvar(thebuf, '').testvar)
+  bwipe!
+
   set fileformats&
 endfunc
 
index a53f44b04a3801dd2c5538fc69f50ea4b48d0a98..38ab5315502419b9d93e635abce6b06257558681 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    507,
 /**/
     506,
 /**/