aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/path.lua9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/path.lua b/src/lib/path.lua
index 925f017..72ea94d 100644
--- a/src/lib/path.lua
+++ b/src/lib/path.lua
@@ -9,6 +9,7 @@ function Path:new(p)
p = p:gsub("^%./", "")
p = p:gsub("/[^/]+/%.%.", "")
p = p:gsub("^[^/]+/%.%./", "")
+ p = p:gsub("^[^/]+/%.%.$", "")
local path = {
segments = p:split('/'),
@@ -34,6 +35,9 @@ function Path:parent()
end
function Path:__tostring()
+ if #self.segments == 0 then
+ return "."
+ end
return (self.is_absolute and "/" or "") .. table.concat(self.segments, "/")
end
@@ -132,8 +136,11 @@ function Path:is_parent_of(child)
end
function Path:relative_to_parent(path)
- if not path:is_parent_of(self) then
+ if #path.segments > 0 and not path:is_parent_of(self) then
+ print('not parent', path, self)
return nil
+ elseif #path.segments == 0 then
+ return Path:new(tostring(self))
end
return Path:new(tostring(self):sub(#tostring(path) + 2))