aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <janedmundlazo@hotmail.com>2018-08-08 21:47:35 -0400
committerJan Edmund Lazo <janedmundlazo@hotmail.com>2018-08-08 21:59:24 -0400
commit3c6eb9871a9a7423e57f5c47e090457b26b6407b (patch)
tree6185ced1b700c88f31f7df3d96e44995982901dd
parent0b3555b5dda477f647653487d6345ce9cc45304c (diff)
downloadrneovim-3c6eb9871a9a7423e57f5c47e090457b26b6407b.tar.gz
rneovim-3c6eb9871a9a7423e57f5c47e090457b26b6407b.tar.bz2
rneovim-3c6eb9871a9a7423e57f5c47e090457b26b6407b.zip
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. https://github.com/vim/vim/commit/8d9f0ef5c6a6f6d19c3d02690e1ee347a70b8452
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/testdir/test_match.vim5
2 files changed, 3 insertions, 6 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 9765b04922..d9765af1dc 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -12424,13 +12424,13 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv,
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
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)));
}
-theend:
xfree(tofree);
p_cpo = save_cpo;
}
diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim
index 066bb2f6a1..5602724b7d 100644
--- a/src/nvim/testdir/test_match.vim
+++ b/src/nvim/testdir/test_match.vim
@@ -152,13 +152,10 @@ endfunc
func Test_matchstrpos()
call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing'))
-
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', 8))
call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
-
call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
endfunc