Mercurial > prosody-hg
comparison spec/util_datamapper_spec.lua @ 11476:83e127eb91f9
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.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 23 Mar 2021 19:52:59 +0100 |
| parents | 348b191cd850 |
| children | 0aa2971380e9 |
comparison
equal
deleted
inserted
replaced
| 11475:9bd36e871f05 | 11476:83e127eb91f9 |
|---|---|
| 1 local st | |
| 1 local xml | 2 local xml |
| 2 local map | 3 local map |
| 3 | 4 |
| 4 setup(function() | 5 setup(function() |
| 6 st = require "util.stanza"; | |
| 5 xml = require "util.xml"; | 7 xml = require "util.xml"; |
| 6 map = require "util.datamapper"; | 8 map = require "util.datamapper"; |
| 7 end); | 9 end); |
| 8 | 10 |
| 9 describe("util.datampper", function() | 11 describe("util.datampper", function() |
| 156 assert.same(d, map.parse(s, x)); | 158 assert.same(d, map.parse(s, x)); |
| 157 end); | 159 end); |
| 158 | 160 |
| 159 it("handles arrays", function () | 161 it("handles arrays", function () |
| 160 assert.same(disco, map.parse(disco_schema, disco_info)); | 162 assert.same(disco, map.parse(disco_schema, disco_info)); |
| 163 end); | |
| 164 | |
| 165 it("deals with locally built stanzas", function() | |
| 166 -- FIXME this could also be argued to be a util.stanza problem | |
| 167 local ver_schema = { | |
| 168 type = "object"; | |
| 169 xml = {name = "iq"}; | |
| 170 properties = { | |
| 171 type = {type = "string"; xml = {attribute = true}}; | |
| 172 id = {type = "string"; xml = {attribute = true}}; | |
| 173 version = { | |
| 174 type = "object"; | |
| 175 xml = {name = "query"; namespace = "jabber:iq:version"}; | |
| 176 properties = {name = "string"; version = "string"; os = "string"}; | |
| 177 }; | |
| 178 }; | |
| 179 }; | |
| 180 local ver_st = st.iq({type = "result"; id = "v1"}) | |
| 181 :query("jabber:iq:version") | |
| 182 :text_tag("name", "Prosody") | |
| 183 :text_tag("version", "trunk") | |
| 184 :text_tag("os", "Lua 5.3") | |
| 185 :reset(); | |
| 186 | |
| 187 local data = {type = "result"; id = "v1"; version = {name = "Prosody"; version = "trunk"; os = "Lua 5.3"}} | |
| 188 assert.same(data, map.parse(ver_schema, ver_st)); | |
| 161 end); | 189 end); |
| 162 | 190 |
| 163 end); | 191 end); |
| 164 | 192 |
| 165 describe("unparse", function() | 193 describe("unparse", function() |
