diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-11-25 21:19:40 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-11-25 23:28:52 +0200 |
commit | adf3a22a1ff154703803827117653aa2400ed08d (patch) | |
tree | b648c1829363490bd55fa998f7b19851d4fc4ed8 | |
parent | 4ff7513fec2df0f079b844c7c558e9ad6c448b16 (diff) | |
download | aconf-adf3a22a1ff154703803827117653aa2400ed08d.tar.bz2 aconf-adf3a22a1ff154703803827117653aa2400ed08d.tar.xz |
model: disallow references to ancestors
-rw-r--r-- | acf2/model/init.lua | 6 | ||||
-rw-r--r-- | acf2/path.lua | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/acf2/model/init.lua b/acf2/model/init.lua index 27a2e32..6b89384 100644 --- a/acf2/model/init.lua +++ b/acf2/model/init.lua @@ -90,9 +90,11 @@ function M.Reference:meta(context) for k, v in node.pairs(obj) do if isinstance(v, node.TreeNode) then v = node.path(v) - v = {value=v, ['ui-value']=pth.name(v), path=true} + v = not pth.is_subordinate(context.path, v) and { + value=v, ['ui-value']=pth.name(v), path=true + } or nil else v = {value=pth.escape(v), ['ui-value']=v} end - table.insert(res.choice, v) + if v then table.insert(res.choice, v) end end return res diff --git a/acf2/path.lua b/acf2/path.lua index a31687d..d080c42 100644 --- a/acf2/path.lua +++ b/acf2/path.lua @@ -77,6 +77,14 @@ function M.is_unique(path) 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 |