Skip to content

Commit d26acde

Browse files
authored
Merge pull request #412 from cameronr/main
fix: Session handling for nvim /
2 parents 9c3f977 + 156c094 commit d26acde

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lua/auto-session/lib.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ end
9797
---Removes the trailing separator (if any) from a directory, for both unix and windows
9898
---This is needed in some places to avoid duplicate separators that complicate
9999
---the path and make equality checks fail (e.g. session control alternate)
100+
-- Will return '/' if that's the only part of the path
100101
---@param dir string The directory path to make sure doesn't have a trailing separator
101102
---@return string Dir guaranteed to not have a trailing separator
102103
function Lib.remove_trailing_separator(dir)
@@ -105,7 +106,7 @@ function Lib.remove_trailing_separator(dir)
105106
dir = dir:gsub("\\$", "")
106107
end
107108

108-
return (dir:gsub("/$", ""))
109+
return (dir:gsub("(.)/$", "%1"))
109110
end
110111

111112
---Legacy decoding function for windows. Replaces ++ with : and - with \

tests/lib_spec.lua

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe("Lib / Helper functions", function()
2424
it("remove_trailing_separator works", function()
2525
assert.equals("/tmp/blah", Lib.remove_trailing_separator "/tmp/blah/")
2626
assert.equals("/tmp/blah", Lib.remove_trailing_separator "/tmp/blah")
27+
assert.equals("/", Lib.remove_trailing_separator "/")
2728

2829
if vim.fn.has "win32" == 1 then
2930
assert.equals("c:\\temp\\blah", Lib.remove_trailing_separator "c:\\temp\\blah\\")

0 commit comments

Comments
 (0)