summaryrefslogtreecommitdiffstats
path: root/aconf/path.lua
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-02-09 19:44:12 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-02-12 16:32:41 +0200
commit29282b5a7d43e8b5ce12b0ec4b7a7620c19a67b6 (patch)
treea8ad7d5343c41950ff9c8f96a55f41a80271f72a /aconf/path.lua
parent07a0eb180872401b271de40190603df8f3ab3db2 (diff)
downloadaconf-29282b5a7d43e8b5ce12b0ec4b7a7620c19a67b6.tar.bz2
aconf-29282b5a7d43e8b5ce12b0ec4b7a7620c19a67b6.tar.xz
proper escaping for back-end addresses
Diffstat (limited to 'aconf/path.lua')
-rw-r--r--aconf/path.lua121
1 files changed, 0 insertions, 121 deletions
diff --git a/aconf/path.lua b/aconf/path.lua
deleted file mode 100644
index 85fc347..0000000
--- a/aconf/path.lua
+++ /dev/null
@@ -1,121 +0,0 @@
---[[
-Copyright (c) 2012-2015 Kaarle Ritvanen
-See LICENSE file for license details
---]]
-
-local M = {}
-
-local map = require('aconf.util').map
-
-
-M.up = {}
-M.wildcard = {}
-local special = {['..']=M.up, ['*']=M.wildcard}
-
-
-function M.is_absolute(path) return path:sub(1, 1) == '/' end
-
-
-function M.escape(comp)
- for symbol, item in pairs(special) do
- if comp == item then return symbol end
- end
- if type(comp) == 'number' then return tostring(comp) end
- local res = comp:gsub('([\\/])', '\\%1')
- return (special[res] or tonumber(res)) and '\\'..res or res
-end
-
-
-function M.rawjoin(p1, p2, ...)
- if not p2 then return p1 end
- if not M.is_absolute(p2) then p2 = '/'..p2 end
- return M.rawjoin((p1 == '/' and '' or p1)..p2, ...)
-end
-
-function M.join(parent, ...)
- local args = map(M.escape, {...})
- if parent > '' then table.insert(args, 1, parent) end
- return M.rawjoin(table.unpack(args))
-end
-
-
-function M.split(path)
- local res = {}
- local comp = ''
- local escaped
-
- local function merge(s)
- if s > '' then
- table.insert(res, not escaped and (special[s] or tonumber(s)) or s)
- end
- end
-
- while true do
- local prefix, sep, suffix = path:match('([^\\/]*)([\\/])(.*)')
- if not prefix then
- merge(comp..path)
- return res
- end
-
- comp = comp..prefix
- if sep == '\\' then
- comp = comp..suffix:sub(1, 1)
- escaped = true
- path = suffix:sub(2, -1)
- else
- merge(comp)
- comp = ''
- escaped = false
- path = suffix
- end
- end
-end
-
-
-function M.is_unique(path)
- for _, comp in ipairs(M.split(path)) do
- if comp == M.wildcard then return false end
- end
- return true
-end
-
-function M.is_subordinate(p1, p2)
- p1 = M.split(p1)
- for i, comp in ipairs(M.split(p2)) do
- if p1[i] ~= comp then return false end
- end
- return true
-end
-
-
-function M.to_absolute(path, base)
- if not M.is_absolute(path) then
- path = base..(base ~= '/' and '/' or '')..path
- end
- local comps = M.split(path)
- local i = 1
- while i <= #comps do
- if comps[i] == M.up then
- if i == 1 then error('Invalid path: '..path) end
- table.remove(comps, i - 1)
- table.remove(comps, i - 1)
- i = i - 1
- else i = i + 1 end
- end
- return M.join('/', table.unpack(comps))
-end
-
-
-function M.parent(path)
- local comps = M.split(path)
- table.remove(comps)
- return M.join('/', table.unpack(comps))
-end
-
-function M.name(path)
- local comps = M.split(path)
- return comps[#comps]
-end
-
-
-return M