aboutsummaryrefslogtreecommitdiff
path: root/src/lib/path.lua
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-04-20 19:30:28 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-04-20 19:30:28 +0200
commite371c801fed71bb73bc7c027e3de5ad2a6116673 (patch)
treee6818b34fed4723d8c44d71f8c6d1a68e44c4c8d /src/lib/path.lua
parent47a5607a691a576928896f21bcf563c011dc64e5 (diff)
add tests and fix path resolution bugHEADmaster
Diffstat (limited to 'src/lib/path.lua')
-rw-r--r--src/lib/path.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/path.lua b/src/lib/path.lua
index a0be1e5..925f017 100644
--- a/src/lib/path.lua
+++ b/src/lib/path.lua
@@ -8,6 +8,7 @@ function Path:new(p)
p = p:gsub("/$", "")
p = p:gsub("^%./", "")
p = p:gsub("/[^/]+/%.%.", "")
+ p = p:gsub("^[^/]+/%.%./", "")
local path = {
segments = p:split('/'),
@@ -126,6 +127,18 @@ function Path:remove(opts)
pipe:close()
end
+function Path:is_parent_of(child)
+ return tostring(child):starts_with(tostring(self))
+end
+
+function Path:relative_to_parent(path)
+ if not path:is_parent_of(self) then
+ return nil
+ end
+
+ return Path:new(tostring(self):sub(#tostring(path) + 2))
+end
+
return {
tests = {
function()