From 2a9d5d386bea8455b37c1accebc45683ec51d6fb Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 12 Dec 2020 18:58:40 +0100 Subject: patch 8.2.2133: Vim9: checking for a non-empty string is too strict Problem: Vim9: checking for a non-empty string is too strict. Solution: Check for any string. (closes #7447) --- src/typval.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/typval.c') diff --git a/src/typval.c b/src/typval.c index 64112e738..affd668e9 100644 --- a/src/typval.c +++ b/src/typval.c @@ -341,14 +341,12 @@ tv_get_float(typval_T *varp) #endif /* - * Give an error and return FAIL unless "tv" is a non-empty string. + * Give an error and return FAIL unless "tv" is a string. */ int check_for_string(typval_T *tv) { - if (tv->v_type != VAR_STRING - || tv->vval.v_string == NULL - || *tv->vval.v_string == NUL) + if (tv->v_type != VAR_STRING) { emsg(_(e_stringreq)); return FAIL; @@ -356,6 +354,22 @@ check_for_string(typval_T *tv) return OK; } +/* + * Give an error and return FAIL unless "tv" is a non-empty string. + */ + int +check_for_nonempty_string(typval_T *tv) +{ + if (check_for_string(tv) == FAIL) + return FAIL; + if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL) + { + emsg(_(e_non_empty_string_required)); + return FAIL; + } + return OK; +} + /* * Get the string value of a variable. * If it is a Number variable, the number is converted into a string. -- cgit v1.2.1