file_pat_to_reg_pat(): handle empty string.

This commit is contained in:
oni-link 2016-01-28 00:45:26 -05:00 committed by Justin M. Keyes
parent 894fcb778e
commit db77b7bc9e
3 changed files with 7 additions and 3 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 || *pat == NUL)
rettv->vval.v_string = (pat == NULL)
? NULL
: file_pat_to_reg_pat(pat, NULL, NULL, false);
}

View File

@ -7119,6 +7119,10 @@ char_u * file_pat_to_reg_pat(
if (pat_end == NULL)
pat_end = pat + STRLEN(pat);
if (pat_end == pat) {
return (char_u *)xstrdup("^$");
}
size_t size = 2; // '^' at start, '$' at end.
for (p = pat; p < pat_end; p++) {

View File

@ -12,8 +12,8 @@ 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('')"))
it('returns ^$ for empty input', function()
eq('^$', eval("glob2regpat('')"))
end)
it('handles valid input', function()
eq('^foo\\.', eval("glob2regpat('foo.*')"))