mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
file_pat_to_reg_pat(): handle empty string.
This commit is contained in:
parent
894fcb778e
commit
db77b7bc9e
@ -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);
|
||||
}
|
||||
|
@ -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++) {
|
||||
|
@ -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.*')"))
|
||||
|
Loading…
Reference in New Issue
Block a user