glob2regpat(): handle empty string.

This commit is contained in:
Justin M. Keyes 2016-01-27 03:26:13 -05:00
parent 765d394f18
commit 894fcb778e
3 changed files with 5 additions and 1 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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')"))