aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-06-21 07:38:43 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-06-23 18:17:08 -0400
commitefdc0f6a6949ec9bfb0d9ef454871458489773f0 (patch)
treeb68e439981c1b1acf2a507cb504678fd1db3750a
parent8bc365c886ecd9ba502dc0d4a7b46ec9bc92387d (diff)
downloadrneovim-efdc0f6a6949ec9bfb0d9ef454871458489773f0.tar.gz
rneovim-efdc0f6a6949ec9bfb0d9ef454871458489773f0.tar.bz2
rneovim-efdc0f6a6949ec9bfb0d9ef454871458489773f0.zip
vim-patch:8.1.0112: no error when using bad arguments with searchpair()
Problem: No error when using bad arguments with searchpair(). Solution: Add error messages. https://github.com/vim/vim/commit/3dddb09c98825acefa6f2d94bb369b8e00d7b3e5
-rw-r--r--src/nvim/eval.c6
-rw-r--r--src/nvim/testdir/test_search.vim16
2 files changed, 17 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 05f001496a..6c138729a2 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -14527,7 +14527,8 @@ static int searchpair_cmn(typval_T *argvars, pos_T *match_pos)
long lnum_stop = 0;
long time_limit = 0;
- // Get the three pattern arguments: start, middle, end.
+ // Get the three pattern arguments: start, middle, end. Will result in an
+ // error if not a valid argument.
char nbuf1[NUMBUFLEN];
char nbuf2[NUMBUFLEN];
const char *spat = tv_get_string_chk(&argvars[0]);
@@ -14566,16 +14567,19 @@ static int searchpair_cmn(typval_T *argvars, pos_T *match_pos)
if (skip->v_type != VAR_FUNC
&& skip->v_type != VAR_PARTIAL
&& skip->v_type != VAR_STRING) {
+ emsgf(_(e_invarg2), tv_get_string(&argvars[4]));
goto theend; // Type error.
}
if (argvars[5].v_type != VAR_UNKNOWN) {
lnum_stop = tv_get_number_chk(&argvars[5], NULL);
if (lnum_stop < 0) {
+ emsgf(_(e_invarg2), tv_get_string(&argvars[5]));
goto theend;
}
if (argvars[6].v_type != VAR_UNKNOWN) {
time_limit = tv_get_number_chk(&argvars[6], NULL);
if (time_limit < 0) {
+ emsgf(_(e_invarg2), tv_get_string(&argvars[6]));
goto theend;
}
}
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index 24ea8cd75a..c455279a59 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -288,16 +288,26 @@ func Test_searchpair()
new
call setline(1, ['other code here', '', '[', '" cursor here', ']'])
4
- let a=searchpair('\[','',']','bW')
+ let a = searchpair('\[','',']','bW')
call assert_equal(3, a)
set nomagic
4
- let a=searchpair('\[','',']','bW')
+ let a = searchpair('\[','',']','bW')
call assert_equal(3, a)
set magic
q!
endfunc
+func Test_searchpair_errors()
+ call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String')
+ call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String')
+ call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String')
+ call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags')
+ call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0')
+ call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99')
+ call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100')
+endfunc
+
func Test_searchpair_skip()
func Zero()
return 0
@@ -312,8 +322,6 @@ func Test_searchpair_skip()
3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0}))
3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero')))
3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0])))
- " invalid argument
- 3 | call assert_equal(0, searchpair('{', '', '}', 'bWn', 0))
bw!
endfunc