aboutsummaryrefslogtreecommitdiffstats
path: root/util/datamapper.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-19 01:17:59 +0100
committerKim Alvefur <zash@zash.se>2021-03-19 01:17:59 +0100
commit7f04df223a369d7d3bb92cf94d0ad64ad5fb6ac9 (patch)
treeae9544ebae148df5f9159b03df6f913ebaa4efb6 /util/datamapper.lua
parent3c3cdcd0c7a6895b90d03480bbc9fba69b74008f (diff)
downloadprosody-7f04df223a369d7d3bb92cf94d0ad64ad5fb6ac9.tar.gz
prosody-7f04df223a369d7d3bb92cf94d0ad64ad5fb6ac9.zip
util.datamapper: Fix arrays nesting one level too deep
Diffstat (limited to 'util/datamapper.lua')
-rw-r--r--util/datamapper.lua18
1 files changed, 9 insertions, 9 deletions
diff --git a/util/datamapper.lua b/util/datamapper.lua
index 65524279..a0c11166 100644
--- a/util/datamapper.lua
+++ b/util/datamapper.lua
@@ -1,5 +1,7 @@
local st = require("util.stanza");
+local schema_t = {}
+
local function toboolean(s)
if s == "true" or s == "1" then
return true
@@ -181,7 +183,7 @@ local function parse(schema, s)
end
end
-local function unparse(schema, t, current_name, current_ns)
+local function unparse(schema, t, current_name, current_ns, ctx)
if schema.xml then
if schema.xml.name then
@@ -193,7 +195,7 @@ local function unparse(schema, t, current_name, current_ns)
end
- local out = st.stanza(current_name, {xmlns = current_ns})
+ local out = ctx or st.stanza(current_name, {xmlns = current_ns})
if schema.type == "object" then
@@ -268,15 +270,13 @@ local function unparse(schema, t, current_name, current_ns)
out:add_direct_child(c);
end
elseif proptype == "array" and type(propschema) == "table" and type(v) == "table" then
- local c = unparse(propschema, v, name, namespace);
- if c then
- if value_where == "in_wrapper" then
- local w = st.stanza(propschema.xml.name or name, {xmlns = propschema.xml.namespace or namespace})
- w:add_direct_child(c);
- out:add_direct_child(w);
- else
+ if value_where == "in_wrapper" then
+ local c = unparse(propschema, v, name, namespace);
+ if c then
out:add_direct_child(c);
end
+ else
+ unparse(propschema, v, name, namespace, out);
end
else
error("NYI")