@@ -330,6 +330,18 @@ arg_string(type_T *type, argcontext_T *context)
330330 return check_arg_type (& t_string , type , context );
331331}
332332
333+ /*
334+ * Check "type" is a bool or number 0 or 1.
335+ */
336+ static int
337+ arg_bool (type_T * type , argcontext_T * context )
338+ {
339+ if (type -> tt_type == VAR_ANY
340+ || type -> tt_type == VAR_NUMBER || type -> tt_type == VAR_BOOL )
341+ return OK ;
342+ return check_arg_type (& t_bool , type , context );
343+ }
344+
333345/*
334346 * Check "type" is a list or a blob.
335347 */
@@ -423,6 +435,7 @@ arg_extend3(type_T *type, argcontext_T *context)
423435/*
424436 * Lists of functions that check the argument types of a builtin function.
425437 */
438+ argcheck_T arg3_string_nr_bool [] = {arg_string , arg_number , arg_bool };
426439argcheck_T arg1_float_or_nr [] = {arg_float_or_nr };
427440argcheck_T arg2_listblob_item [] = {arg_list_or_blob , arg_item_of_prev };
428441argcheck_T arg23_extend [] = {arg_list_or_dict , arg_same_as_prev , arg_extend3 };
@@ -1552,7 +1565,7 @@ static funcentry_T global_functions[] =
15521565 ret_float , FLOAT_FUNC (f_str2float )},
15531566 {"str2list" , 1 , 2 , FEARG_1 , NULL ,
15541567 ret_list_number , f_str2list },
1555- {"str2nr" , 1 , 3 , FEARG_1 , NULL ,
1568+ {"str2nr" , 1 , 3 , FEARG_1 , arg3_string_nr_bool ,
15561569 ret_number , f_str2nr },
15571570 {"strcharpart" , 2 , 3 , FEARG_1 , NULL ,
15581571 ret_string , f_strcharpart },
@@ -9076,7 +9089,7 @@ f_str2nr(typval_T *argvars, typval_T *rettv)
90769089 what |= STR2NR_QUOTE ;
90779090 }
90789091
9079- p = skipwhite (tv_get_string (& argvars [0 ]));
9092+ p = skipwhite (tv_get_string_strict (& argvars [0 ]));
90809093 isneg = (* p == '-' );
90819094 if (* p == '+' || * p == '-' )
90829095 p = skipwhite (p + 1 );
0 commit comments