mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
vim-patch:8.0.1004: matchstrpos() without a match returns too many items
Problem: Matchstrpos() without a match returns too many items.
Solution: Also remove the second item when the position is beyond the end of
the string. (Hirohito Higashi) Use an enum for the type.
8d9f0ef5c6
This commit is contained in:
@@ -12424,13 +12424,13 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv,
|
|||||||
vim_regfree(regmatch.regprog);
|
vim_regfree(regmatch.regprog);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == kSomeMatchStrPos && l == NULL) {
|
theend:
|
||||||
|
if (type == kSomeMatchStrPos && l == NULL && rettv->vval.v_list != NULL) {
|
||||||
// matchstrpos() without a list: drop the second item
|
// matchstrpos() without a list: drop the second item
|
||||||
list_T *const ret_l = rettv->vval.v_list;
|
list_T *const ret_l = rettv->vval.v_list;
|
||||||
tv_list_item_remove(ret_l, TV_LIST_ITEM_NEXT(ret_l, tv_list_first(ret_l)));
|
tv_list_item_remove(ret_l, TV_LIST_ITEM_NEXT(ret_l, tv_list_first(ret_l)));
|
||||||
}
|
}
|
||||||
|
|
||||||
theend:
|
|
||||||
xfree(tofree);
|
xfree(tofree);
|
||||||
p_cpo = save_cpo;
|
p_cpo = save_cpo;
|
||||||
}
|
}
|
||||||
|
@@ -152,13 +152,10 @@ endfunc
|
|||||||
|
|
||||||
func Test_matchstrpos()
|
func Test_matchstrpos()
|
||||||
call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing'))
|
call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing'))
|
||||||
|
|
||||||
call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2))
|
call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2))
|
||||||
|
|
||||||
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5))
|
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5))
|
||||||
|
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8))
|
||||||
call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
|
call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
|
||||||
|
|
||||||
call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
|
call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user