Skip to content

Commit

Permalink
fix: make sure realpath and path's ends are matched
Browse files Browse the repository at this point in the history
e.g.
  /path/to/me ../to/me
  /path/to/me/ ../to/me/
  • Loading branch information
PannenetsF committed Jun 15, 2024
1 parent 99d8313 commit d994553
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/orgmode/org/hyperlinks/url.lua
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function Url:_parse_path_type()
or (first_char == '~' and self.path:sub(2, 2) == '/')
then
self.path_type = 'file'
self.realpath = fs.substitute_path(self.path) or self.path
self.realpath = fs.get_real_path(self.path, true) or self.path
return
end

Expand Down
8 changes: 7 additions & 1 deletion lua/orgmode/utils/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function M.substitute_path(path_str)
end

---@param filepath string
function M.get_real_path(filepath)
function M.get_real_path(filepath, match)
if not filepath then
return false
end
Expand All @@ -30,6 +30,12 @@ function M.get_real_path(filepath)
return false
end
local real = vim.loop.fs_realpath(substituted)
if match then
-- if path ends with / , real needs too
if filepath:sub(-1, -1) == '/' then
real = real .. '/'
end
end
return real or false
end

Expand Down

0 comments on commit d994553

Please sign in to comment.