aboutsummaryrefslogtreecommitdiffstats
path: root/teal-src
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-23 19:52:59 +0100
committerKim Alvefur <zash@zash.se>2021-03-23 19:52:59 +0100
commit204014578019d24c458550bad8fdb544b95190b3 (patch)
tree6289e53c8a608c6a6c33361810176d263ff4b2ef /teal-src
parente783d99cc2eb5703de84757e8ac7346946a77648 (diff)
downloadprosody-204014578019d24c458550bad8fdb544b95190b3.tar.gz
prosody-204014578019d24c458550bad8fdb544b95190b3.zip
util.datamapper: Deal with locally built stanzas missing xmlns
So the problem is that xmlns is not inherited when building a stanza, and then :get_child(n, ns) with an explicit namespace does not find that such child tags. E.g. local t = st.stanza("foo", { xmlns = "urn:example:bar" }) :text_tag("hello", "world"); assert(t:get_child("hello", "urn:example:bar"), "This fails"); Meanwhile, during parsing (util.xmppstream or util.xml) child tags do get the parents xmlns when not overriding them. Thus, in the above example, if the stanza is passed trough `t = util.xml.parse(tostring(t))` then the assert succeeds. This change makes it so that it leaves out the namespace argument to :get_child when it is the same as the current/parent namespace, which behaves the same for both built and parsed stanzas.
Diffstat (limited to 'teal-src')
-rw-r--r--teal-src/util/datamapper.tl10
1 files changed, 5 insertions, 5 deletions
diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl
index 39d35e82..0d757800 100644
--- a/teal-src/util/datamapper.tl
+++ b/teal-src/util/datamapper.tl
@@ -61,7 +61,7 @@ local function unpack_propschema( propschema : schema_t, propname : string, curr
local proptype : json_type_name = "string"
local value_where : value_goes = propname and "in_text_tag" or "in_text"
local name = propname
- local namespace = current_ns
+ local namespace : string
local prefix : string
local single_attribute : string
local enums : { any }
@@ -82,7 +82,7 @@ local function unpack_propschema( propschema : schema_t, propname : string, curr
if xml.name then
name = xml.name
end
- if xml.namespace then
+ if xml.namespace and xml.namespace ~= current_ns then
namespace = xml.namespace
end
if xml.prefix then
@@ -137,7 +137,7 @@ local function extract_value (s : st.stanza_t, value_where : value_goes, proptyp
local attr = name
if prefix then
attr = prefix .. ':' .. name
- elseif namespace ~= s.attr.xmlns then
+ elseif namespace and namespace ~= s.attr.xmlns then
attr = namespace .. "\1" .. name
end
return s.attr[attr]
@@ -250,7 +250,7 @@ local function unparse_property(out : st.stanza_t, v : any, proptype : json_type
local attr = name
if prefix then
attr = prefix .. ':' .. name
- elseif namespace ~= current_ns then
+ elseif namespace and namespace ~= current_ns then
attr = namespace .. "\1" .. name
end
@@ -261,7 +261,7 @@ local function unparse_property(out : st.stanza_t, v : any, proptype : json_type
assert(single_attribute)
local propattr : { string : string } = {}
- if namespace ~= current_ns then
+ if namespace and namespace ~= current_ns then
propattr.xmlns = namespace
end