aboutsummaryrefslogtreecommitdiffstats
path: root/spec
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 /spec
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 'spec')
-rw-r--r--spec/util_datamapper_spec.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/util_datamapper_spec.lua b/spec/util_datamapper_spec.lua
index 37b3e3b6..8a4eacfa 100644
--- a/spec/util_datamapper_spec.lua
+++ b/spec/util_datamapper_spec.lua
@@ -1,7 +1,9 @@
+local st
local xml
local map
setup(function()
+ st = require "util.stanza";
xml = require "util.xml";
map = require "util.datamapper";
end);
@@ -160,6 +162,32 @@ describe("util.datampper", function()
assert.same(disco, map.parse(disco_schema, disco_info));
end);
+ it("deals with locally built stanzas", function()
+ -- FIXME this could also be argued to be a util.stanza problem
+ local ver_schema = {
+ type = "object";
+ xml = {name = "iq"};
+ properties = {
+ type = {type = "string"; xml = {attribute = true}};
+ id = {type = "string"; xml = {attribute = true}};
+ version = {
+ type = "object";
+ xml = {name = "query"; namespace = "jabber:iq:version"};
+ properties = {name = "string"; version = "string"; os = "string"};
+ };
+ };
+ };
+ local ver_st = st.iq({type = "result"; id = "v1"})
+ :query("jabber:iq:version")
+ :text_tag("name", "Prosody")
+ :text_tag("version", "trunk")
+ :text_tag("os", "Lua 5.3")
+ :reset();
+
+ local data = {type = "result"; id = "v1"; version = {name = "Prosody"; version = "trunk"; os = "Lua 5.3"}}
+ assert.same(data, map.parse(ver_schema, ver_st));
+ end);
+
end);
describe("unparse", function()