summaryrefslogtreecommitdiffstats
path: root/acf/path.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acf/path.lua')
-rw-r--r--acf/path.lua20
1 files changed, 13 insertions, 7 deletions
diff --git a/acf/path.lua b/acf/path.lua
index f18d701..b915012 100644
--- a/acf/path.lua
+++ b/acf/path.lua
@@ -31,25 +31,29 @@ end
local function escape(comp)
+ if type(comp) == 'number' then return tostring(comp) end
local res = string.gsub(comp, '([\\/])', '\\%1')
- return res
+ return tonumber(res) and '\\'..res or res
end
-function join(parent, name) return mjoin(parent, escape(name)) end
-
-function mjoin(p1, p2, ...)
+function rawjoin(p1, p2, ...)
if not p2 then return p1 end
if not is_absolute(p2) then p2 = '/'..p2 end
- return mjoin((p1 == '/' and '' or p1)..p2, unpack(arg))
+ return rawjoin((p1 == '/' and '' or p1)..p2, unpack(arg))
end
+function join(parent, ...) return rawjoin(parent, unpack(map(escape, arg))) end
+
function split(path)
local res = {}
local comp = ''
+ local escaped
- local function merge(s) if s > '' then table.insert(res, s) end end
+ local function merge(s)
+ if s > '' then table.insert(res, not escaped and tonumber(s) or s) end
+ end
while true do
local prefix, sep, suffix = string.match(path, '([^\\/]*)([\\/])(.*)')
@@ -61,10 +65,12 @@ function split(path)
comp = comp..prefix
if sep == '\\' then
comp = comp..string.sub(suffix, 1, 1)
+ escaped = true
path = string.sub(suffix, 2, -1)
else
merge(comp)
comp = ''
+ escaped = false
path = suffix
end
end
@@ -74,7 +80,7 @@ end
function parent(path)
local comps = split(path)
table.remove(comps)
- return mjoin('/', unpack(map(escape, comps)))
+ return join('/', unpack(comps))
end
function name(path)