mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2920: still a way to shadow a builtin function
Problem: Still a way to shadow a builtin function. (Yasuhiro Matsumoto) Solution: Check the key when using extend(). (issue #8302)
This commit is contained in:
18
src/dict.c
18
src/dict.c
@@ -344,6 +344,20 @@ dict_copy(dict_T *orig, int deep, int copyID)
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for adding a function to g: or s:.
|
||||||
|
* If the name is wrong give an error message and return TRUE.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
dict_wrong_func_name(dict_T *d, typval_T *tv, char_u *name)
|
||||||
|
{
|
||||||
|
return (d == get_globvar_dict()
|
||||||
|
|| (SCRIPT_ID_VALID(current_sctx.sc_sid)
|
||||||
|
&& d == &SCRIPT_ITEM(current_sctx.sc_sid)->sn_vars->sv_dict))
|
||||||
|
&& (tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
|
||||||
|
&& var_wrong_func_name(name, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add item "item" to Dictionary "d".
|
* Add item "item" to Dictionary "d".
|
||||||
* Returns FAIL when out of memory and when key already exists.
|
* Returns FAIL when out of memory and when key already exists.
|
||||||
@@ -351,6 +365,8 @@ dict_copy(dict_T *orig, int deep, int copyID)
|
|||||||
int
|
int
|
||||||
dict_add(dict_T *d, dictitem_T *item)
|
dict_add(dict_T *d, dictitem_T *item)
|
||||||
{
|
{
|
||||||
|
if (dict_wrong_func_name(d, &item->di_tv, item->di_key))
|
||||||
|
return FAIL;
|
||||||
return hash_add(&d->dv_hashtab, item->di_key);
|
return hash_add(&d->dv_hashtab, item->di_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1109,6 +1125,8 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action)
|
|||||||
if (value_check_lock(di1->di_tv.v_lock, arg_errmsg, TRUE)
|
if (value_check_lock(di1->di_tv.v_lock, arg_errmsg, TRUE)
|
||||||
|| var_check_ro(di1->di_flags, arg_errmsg, TRUE))
|
|| var_check_ro(di1->di_flags, arg_errmsg, TRUE))
|
||||||
break;
|
break;
|
||||||
|
if (dict_wrong_func_name(d1, &HI2DI(hi2)->di_tv, hi2->hi_key))
|
||||||
|
break;
|
||||||
clear_tv(&di1->di_tv);
|
clear_tv(&di1->di_tv);
|
||||||
copy_tv(&HI2DI(hi2)->di_tv, &di1->di_tv);
|
copy_tv(&HI2DI(hi2)->di_tv, &di1->di_tv);
|
||||||
}
|
}
|
||||||
|
@@ -1462,12 +1462,8 @@ set_var_lval(
|
|||||||
semsg(_(e_dictkey), lp->ll_newkey);
|
semsg(_(e_dictkey), lp->ll_newkey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((lp->ll_tv->vval.v_dict == get_globvar_dict()
|
if (dict_wrong_func_name(lp->ll_tv->vval.v_dict, rettv,
|
||||||
|| lp->ll_tv->vval.v_dict ==
|
lp->ll_newkey))
|
||||||
&SCRIPT_ITEM(current_sctx.sc_sid)->sn_vars->sv_dict)
|
|
||||||
&& (rettv->v_type == VAR_FUNC
|
|
||||||
|| rettv->v_type == VAR_PARTIAL)
|
|
||||||
&& var_wrong_func_name(lp->ll_newkey, TRUE))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Need to add an item to the Dictionary.
|
// Need to add an item to the Dictionary.
|
||||||
|
@@ -13,6 +13,7 @@ dictitem_T *dictitem_alloc(char_u *key);
|
|||||||
void dictitem_remove(dict_T *dict, dictitem_T *item);
|
void dictitem_remove(dict_T *dict, dictitem_T *item);
|
||||||
void dictitem_free(dictitem_T *item);
|
void dictitem_free(dictitem_T *item);
|
||||||
dict_T *dict_copy(dict_T *orig, int deep, int copyID);
|
dict_T *dict_copy(dict_T *orig, int deep, int copyID);
|
||||||
|
int dict_wrong_func_name(dict_T *d, typval_T *tv, char_u *name);
|
||||||
int dict_add(dict_T *d, dictitem_T *item);
|
int dict_add(dict_T *d, dictitem_T *item);
|
||||||
int dict_add_number(dict_T *d, char *key, varnumber_T nr);
|
int dict_add_number(dict_T *d, char *key, varnumber_T nr);
|
||||||
int dict_add_bool(dict_T *d, char *key, varnumber_T nr);
|
int dict_add_bool(dict_T *d, char *key, varnumber_T nr);
|
||||||
|
@@ -2686,6 +2686,11 @@ func Test_builtin_check()
|
|||||||
call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:')
|
call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:')
|
||||||
call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:')
|
call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:')
|
||||||
call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:')
|
call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:')
|
||||||
|
|
||||||
|
call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:')
|
||||||
|
let g:bar = 123
|
||||||
|
call extend(g:, #{bar: { -> "foo" }}, "keep")
|
||||||
|
call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2920,
|
||||||
/**/
|
/**/
|
||||||
2919,
|
2919,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user