mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:7.4.2002
Problem: Crash when passing number to filter() or map().
Solution: Convert to a string. (Ozaki Kiichi)
a06ec8f345
This commit is contained in:
parent
bb2afeb026
commit
6c423989fc
@ -9414,7 +9414,8 @@ static void filter_map(typval_T *argvars, typval_T *rettv, int map)
|
|||||||
static int filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp)
|
static int filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp)
|
||||||
{
|
{
|
||||||
typval_T rettv;
|
typval_T rettv;
|
||||||
typeval_T argv[3];
|
typval_T argv[3];
|
||||||
|
char_u buf[NUMBUFLEN];
|
||||||
char_u *s;
|
char_u *s;
|
||||||
int retval = FAIL;
|
int retval = FAIL;
|
||||||
int dummy;
|
int dummy;
|
||||||
@ -9424,6 +9425,7 @@ static int filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp)
|
|||||||
argv[1] = vimvars[VV_VAL].vv_tv;
|
argv[1] = vimvars[VV_VAL].vv_tv;
|
||||||
s = expr->vval.v_string;
|
s = expr->vval.v_string;
|
||||||
if (expr->v_type == VAR_FUNC) {
|
if (expr->v_type == VAR_FUNC) {
|
||||||
|
s = expr->vval.v_string;
|
||||||
if (call_func(s, (int)STRLEN(s), &rettv, 2, argv, 0L, 0L, &dummy,
|
if (call_func(s, (int)STRLEN(s), &rettv, 2, argv, 0L, 0L, &dummy,
|
||||||
true, NULL, NULL) == FAIL) {
|
true, NULL, NULL) == FAIL) {
|
||||||
goto theend;
|
goto theend;
|
||||||
@ -9437,6 +9439,10 @@ static int filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
s = get_tv_string_buf_chk(expr, buf);
|
||||||
|
if (s == NULL) {
|
||||||
|
goto theend;
|
||||||
|
}
|
||||||
s = skipwhite(s);
|
s = skipwhite(s);
|
||||||
if (eval1(&s, &rettv, true) == FAIL) {
|
if (eval1(&s, &rettv, true) == FAIL) {
|
||||||
goto theend;
|
goto theend;
|
||||||
|
@ -5,10 +5,12 @@ func Test_filter_map_list_expr_string()
|
|||||||
" filter()
|
" filter()
|
||||||
call assert_equal([2, 3, 4], filter([1, 2, 3, 4], 'v:val > 1'))
|
call assert_equal([2, 3, 4], filter([1, 2, 3, 4], 'v:val > 1'))
|
||||||
call assert_equal([3, 4], filter([1, 2, 3, 4], 'v:key > 1'))
|
call assert_equal([3, 4], filter([1, 2, 3, 4], 'v:key > 1'))
|
||||||
|
call assert_equal([], filter([1, 2, 3, 4], 0))
|
||||||
|
|
||||||
" map()
|
" map()
|
||||||
call assert_equal([2, 4, 6, 8], map([1, 2, 3, 4], 'v:val * 2'))
|
call assert_equal([2, 4, 6, 8], map([1, 2, 3, 4], 'v:val * 2'))
|
||||||
call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], 'v:key * 2'))
|
call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], 'v:key * 2'))
|
||||||
|
call assert_equal([9, 9, 9, 9], map([1, 2, 3, 4], 9))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" dict with expression string
|
" dict with expression string
|
||||||
@ -18,10 +20,12 @@ func Test_filter_map_dict_expr_string()
|
|||||||
" filter()
|
" filter()
|
||||||
call assert_equal({"bar": 2, "baz": 3}, filter(copy(dict), 'v:val > 1'))
|
call assert_equal({"bar": 2, "baz": 3}, filter(copy(dict), 'v:val > 1'))
|
||||||
call assert_equal({"foo": 1, "baz": 3}, filter(copy(dict), 'v:key > "bar"'))
|
call assert_equal({"foo": 1, "baz": 3}, filter(copy(dict), 'v:key > "bar"'))
|
||||||
|
call assert_equal({}, filter(copy(dict), 0))
|
||||||
|
|
||||||
" map()
|
" map()
|
||||||
call assert_equal({"foo": 2, "bar": 4, "baz": 6}, map(copy(dict), 'v:val * 2'))
|
call assert_equal({"foo": 2, "bar": 4, "baz": 6}, map(copy(dict), 'v:val * 2'))
|
||||||
call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), 'v:key[0]'))
|
call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), 'v:key[0]'))
|
||||||
|
call assert_equal({"foo": 9, "bar": 9, "baz": 9}, map(copy(dict), 9))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" list with funcref
|
" list with funcref
|
||||||
|
@ -438,7 +438,7 @@ static int included_patches[] = {
|
|||||||
2005,
|
2005,
|
||||||
// 2004 NA
|
// 2004 NA
|
||||||
// 2003 NA
|
// 2003 NA
|
||||||
// 2002,
|
2002,
|
||||||
// 2001 NA
|
// 2001 NA
|
||||||
2000,
|
2000,
|
||||||
1999,
|
1999,
|
||||||
|
Loading…
Reference in New Issue
Block a user