diff options
-rw-r--r-- | src/nvim/eval.c | 2 | ||||
-rw-r--r-- | src/nvim/fileio.c | 1 | ||||
-rw-r--r-- | test/functional/legacy/glob2regpat_spec.lua | 3 |
3 files changed, 5 insertions, 1 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 33c584eede..25f3cbf180 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10792,7 +10792,7 @@ static void f_glob2regpat(typval_T *argvars, typval_T *rettv) char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error rettv->v_type = VAR_STRING; - rettv->vval.v_string = (pat == NULL) + rettv->vval.v_string = (pat == NULL || *pat == NUL) ? NULL : file_pat_to_reg_pat(pat, NULL, NULL, false); } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 26376afa27..3256004153 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -7106,6 +7106,7 @@ char_u * file_pat_to_reg_pat( char *allow_dirs, // Result passed back out in here int no_bslash // Don't use a backward slash as pathsep ) + FUNC_ATTR_NONNULL_ARG(1) { const char_u *endp; char_u *reg_pat; diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua index 373aad68a1..25f0ffd007 100644 --- a/test/functional/legacy/glob2regpat_spec.lua +++ b/test/functional/legacy/glob2regpat_spec.lua @@ -12,6 +12,9 @@ describe('glob2regpat()', function() helpers.feed('<cr>') neq(nil, string.find(eval('v:errmsg'), '^E806:')) end) + it('returns empty string for empty input', function() + eq('', eval("glob2regpat('')")) + end) it('handles valid input', function() eq('^foo\\.', eval("glob2regpat('foo.*')")) eq('\\.vim$', eval("glob2regpat('*.vim')")) |