File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -340,7 +340,7 @@ function Path:normalize(cwd)
340
340
self :make_relative (cwd )
341
341
342
342
-- Substitute home directory w/ "~"
343
- self .filename = self .filename :gsub (" ^" .. path .home , " ~" , 1 )
343
+ self .filename = self .filename :gsub (" ^" .. path .home , " ~" .. path . sep , 1 )
344
344
345
345
return _normalize_path (self .filename , self ._cwd )
346
346
end
Original file line number Diff line number Diff line change @@ -205,6 +205,22 @@ describe("Path", function()
205
205
p ._cwd = " /tmp/lua"
206
206
assert .are .same (" /tmp/lua/plenary/path.lua" , p :normalize ())
207
207
end )
208
+
209
+ it (" can normalize ~ when file is within home directory (traling slash)" , function ()
210
+ local home = " /home/test/"
211
+ local p = Path :new { home , " ./test_file" }
212
+ p .path .home = home
213
+ p ._cwd = " /tmp/lua"
214
+ assert .are .same (" ~/./test_file" , p :normalize ())
215
+ end )
216
+
217
+ it (" can normalize ~ when file is within home directory (no trailing slash)" , function ()
218
+ local home = " /home/test"
219
+ local p = Path :new { home , " ./test_file" }
220
+ p .path .home = home
221
+ p ._cwd = " /tmp/lua"
222
+ assert .are .same (" ~//./test_file" , p :normalize ())
223
+ end )
208
224
end )
209
225
210
226
describe (" :shorten" , function ()
You can’t perform that action at this time.
0 commit comments