diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-09-08 11:13:42 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-09-18 14:35:26 -0300 |
commit | c708061a5a9b1bb75f06c6de0b5c02f3a0abad4d (patch) | |
tree | 1a812cdb3886b0184221f10d915f1fd651e564ae | |
parent | 29b998be68191b96543151e692dce9f790d0f552 (diff) | |
download | rneovim-c708061a5a9b1bb75f06c6de0b5c02f3a0abad4d.tar.gz rneovim-c708061a5a9b1bb75f06c6de0b5c02f3a0abad4d.tar.bz2 rneovim-c708061a5a9b1bb75f06c6de0b5c02f3a0abad4d.zip |
os/path: Fix path_get_absolute_path for top-level paths
Close #2833
-rw-r--r-- | src/nvim/path.c | 11 | ||||
-rw-r--r-- | test/unit/path_spec.lua | 8 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 1a1f15e8f3..45ae12b78a 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2089,8 +2089,15 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, int len, int // expand it if forced or not an absolute path if (force || !path_is_absolute_path(fname)) { if ((p = vim_strrchr(fname, '/')) != NULL) { - STRNCPY(relative_directory, fname, p-fname); - relative_directory[p-fname] = NUL; + // relative to root + if (p == fname) { + // only one path component + relative_directory[0] = '/'; + relative_directory[1] = NUL; + } else { + STRNCPY(relative_directory, fname, p-fname); + relative_directory[p-fname] = NUL; + } end_of_path = (char *) (p + 1); } else { relative_directory[0] = NUL; diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 261d797624..239a255151 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -416,6 +416,14 @@ describe('more path function', function() eq('unit-test-directory/test.file', (ffi.string(filename))) eq(OK, result) end) + + it('works with directories that have one path component', function() + local force_expansion = 1 + local filename = to_cstr('/tmp') + local result = path.vim_FullName(filename, buffer, len, force_expansion) + eq('/tmp', ffi.string(buffer)) + eq(OK, result) + end) end) describe('path_fix_case', function() |