From 0eb24f00658251ffda416a29a29ad4e02165d368 Mon Sep 17 00:00:00 2001 From: Brian Ryall Date: Sun, 18 Apr 2021 21:57:09 -0400 Subject: [PATCH 1/2] think _normalize_path should return absolute path according to absolute() --- lua/plenary/path.lua | 2 +- tests/plenary/path_spec.lua | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/plenary/path.lua b/lua/plenary/path.lua index 1478008f..796661e3 100644 --- a/lua/plenary/path.lua +++ b/lua/plenary/path.lua @@ -88,7 +88,7 @@ local function _normalize_path(filename) idx = idx + 1 until idx > #parts - out_file = table.concat(parts, path.sep) + out_file = path.sep .. table.concat(parts, path.sep) end return out_file diff --git a/tests/plenary/path_spec.lua b/tests/plenary/path_spec.lua index 9f0750ee..96707098 100644 --- a/tests/plenary/path_spec.lua +++ b/tests/plenary/path_spec.lua @@ -158,22 +158,22 @@ describe('Path', function() describe(':normalize', function() it('can take paths with double separators change them to single separators', function() - local orig = 'lua//plenary/path.lua' + local orig = '/lua//plenary/path.lua' local final = Path:new(orig):normalize() - assert.are.same(final, 'lua/plenary/path.lua') + assert.are.same(final, '/lua/plenary/path.lua') end) -- this may be redundant since normalize just calls make_relative which is tested above it('can take absolute paths with double seps' .. 'and make them relative with single seps', function() - local orig = vim.loop.cwd() .. '/lua//plenary/path.lua' + local orig = '/lua//plenary/path.lua' local final = Path:new(orig):normalize() - assert.are.same(final, 'lua/plenary/path.lua') + assert.are.same(final, '/lua/plenary/path.lua') end) it('can remove the .. in paths', function() - local orig = 'lua//plenary/path.lua/foo/bar/../..' + local orig = '/lua//plenary/path.lua/foo/bar/../..' local final = Path:new(orig):normalize() - assert.are.same(final, 'lua/plenary/path.lua') + assert.are.same(final, '/lua/plenary/path.lua') end) end) From 0802607f461d3b96653997e6e627e264c1732edc Mon Sep 17 00:00:00 2001 From: Brian Ryall Date: Sun, 18 Apr 2021 22:26:46 -0400 Subject: [PATCH 2/2] fix _normalize_path by not path.sep but with path.root --- lua/plenary/path.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/plenary/path.lua b/lua/plenary/path.lua index 796661e3..6bccac23 100644 --- a/lua/plenary/path.lua +++ b/lua/plenary/path.lua @@ -88,7 +88,7 @@ local function _normalize_path(filename) idx = idx + 1 until idx > #parts - out_file = path.sep .. table.concat(parts, path.sep) + out_file = path.root(filename) .. table.concat(parts, path.sep) end return out_file