aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/eval.c12
-rw-r--r--src/nvim/fileio.c5
-rw-r--r--src/nvim/version.c6
-rw-r--r--test/functional/legacy/glob2regpat_spec.lua22
4 files changed, 39 insertions, 6 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 22ff7988f3..a1c5f958d1 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -10822,15 +10822,15 @@ static void f_globpath(typval_T *argvars, typval_T *rettv)
}
}
-/*
- * "glob2regpat()" function
- */
+// "glob2regpat()" function
static void f_glob2regpat(typval_T *argvars, typval_T *rettv)
{
- char_u *pat = get_tv_string_chk(&argvars[0]);
+ char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error
- rettv->v_type = VAR_STRING;
- rettv->vval.v_string = file_pat_to_reg_pat(pat, NULL, NULL, FALSE);
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = (pat == NULL)
+ ? NULL
+ : file_pat_to_reg_pat(pat, NULL, NULL, false);
}
/*
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index c095a7d27f..badb5b85b0 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;
@@ -7118,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++) {
diff --git a/src/nvim/version.c b/src/nvim/version.c
index bf1986d3ba..c73c7805a7 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -69,6 +69,12 @@ static char *features[] = {
// clang-format off
static int included_patches[] = {
+ 1081,
+
+
+
+
+
1055,
// 1054,
// 1053,
diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua
new file mode 100644
index 0000000000..357128bcb6
--- /dev/null
+++ b/test/functional/legacy/glob2regpat_spec.lua
@@ -0,0 +1,22 @@
+-- Tests for signs
+
+local helpers = require('test.functional.helpers')
+local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
+local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval
+
+describe('glob2regpat()', function()
+ before_each(clear)
+
+ it('handles invalid input', function()
+ execute('call glob2regpat(1.33)')
+ helpers.feed('<cr>')
+ neq(nil, string.find(eval('v:errmsg'), '^E806:'))
+ end)
+ it('returns ^$ for empty input', function()
+ eq('^$', eval("glob2regpat('')"))
+ end)
+ it('handles valid input', function()
+ eq('^foo\\.', eval("glob2regpat('foo.*')"))
+ eq('\\.vim$', eval("glob2regpat('*.vim')"))
+ end)
+end)