From 7f04df223a369d7d3bb92cf94d0ad64ad5fb6ac9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 19 Mar 2021 01:17:59 +0100 Subject: util.datamapper: Fix arrays nesting one level too deep --- util/datamapper.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'util/datamapper.lua') 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") -- cgit v1.2.3