aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/fileio.c5
-rw-r--r--src/nvim/path.c29
-rw-r--r--test/functional/eval/glob_spec.lua21
3 files changed, 48 insertions, 7 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index dee9680230..58e4873e00 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -415,14 +415,11 @@ readfile (
msg_scroll = TRUE; /* don't overwrite previous file message */
/*
- * If the name ends in a path separator, we can't open it. Check here,
- * because reading the file may actually work, but then creating the swap
- * file may destroy it! Reported on MS-DOS and Win 95.
* If the name is too long we might crash further on, quit here.
*/
if (fname != NULL && *fname != NUL) {
p = fname + STRLEN(fname);
- if (after_pathsep((char *)fname, (char *)p) || STRLEN(fname) >= MAXPATHL) {
+ if (STRLEN(fname) >= MAXPATHL) {
filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0);
msg_end();
msg_scroll = msg_save;
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 152154e5f4..9d9cd933b4 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -481,6 +481,28 @@ static size_t path_expand(garray_T *gap, const char_u *path, int flags)
return do_path_expand(gap, path, 0, flags, false);
}
+static const char *scandir_next_with_dots(Directory *dir)
+{
+ static int count = 0;
+ const char *entry = NULL;
+ if (dir == NULL) {
+ count = 0;
+ } else {
+ count += 1;
+ if (count == 1) {
+ entry = ".";
+ } else if (count == 2) {
+ entry = "..";
+ } else {
+ entry = os_scandir_next(dir);
+ if (entry == NULL) {
+ count = 0;
+ }
+ }
+ }
+ return entry;
+}
+
/// Implementation of path_expand().
///
/// Chars before `path + wildoff` do not get expanded.
@@ -597,11 +619,12 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
*s = NUL;
Directory dir;
- // open the directory for scanning
- if (os_scandir(&dir, *buf == NUL ? "." : (char *)buf)) {
+ if (os_scandir(&dir, *buf == NUL ? "." : (char *)buf)
+ || os_isdir(*buf == NUL ? (char_u *)"." : (char_u *)buf)) {
// Find all matching entries.
char_u *name;
- while((name = (char_u *) os_scandir_next(&dir))) {
+ scandir_next_with_dots(NULL);
+ while((name = (char_u *) scandir_next_with_dots(&dir)) && name != NULL) {
if ((name[0] != '.' || starts_with_dot)
&& ((regmatch.regprog != NULL && vim_regexec(&regmatch, name, 0))
|| ((flags & EW_NOTWILD)
diff --git a/test/functional/eval/glob_spec.lua b/test/functional/eval/glob_spec.lua
new file mode 100644
index 0000000000..977b82d733
--- /dev/null
+++ b/test/functional/eval/glob_spec.lua
@@ -0,0 +1,21 @@
+local helpers = require('test.functional.helpers')
+local clear, execute, eval, eq = helpers.clear, helpers.execute, helpers.eval, helpers.eq
+
+before_each(function()
+ clear()
+ lfs.mkdir('test-glob')
+ execute('cd test-glob')
+end)
+
+after_each(function()
+ lfs.rmdir('test-glob')
+end)
+
+describe('glob()', function()
+ it("glob('.*') returns . and .. ", function()
+ eq({'.', '..'}, eval("glob('.*', 0, 1)"))
+ end)
+ it("glob('*') returns an empty list ", function()
+ eq({}, eval("glob('*', 0, 1)"))
+ end)
+end)