Software /
code /
prosody
Changeset
9675:7d8e08f80dbd
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 02 Dec 2018 02:38:36 +0100 |
parents | 9671:e50559a42dfe (current diff) 9674:6f97acc4583b (diff) |
children | 9676:837ba29aaeff |
files | |
diffstat | 3 files changed, 37 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_vcard_legacy.lua Sat Dec 01 22:13:24 2018 +0000 +++ b/plugins/mod_vcard_legacy.lua Sun Dec 02 02:38:36 2018 +0100 @@ -274,6 +274,7 @@ local origin, stanza = event.origin, event.stanza; local username = origin.username; if not username then return end + if stanza.attr.type then return end local pep_service = mod_pep.get_pep_service(username); stanza:remove_children("x", "vcard-temp:x:update");
--- a/spec/util_stanza_spec.lua Sat Dec 01 22:13:24 2018 +0000 +++ b/spec/util_stanza_spec.lua Sun Dec 02 02:38:36 2018 +0100 @@ -4,23 +4,33 @@ describe("util.stanza", function() describe("#preserialize()", function() it("should work", function() - local stanza = st.stanza("message", { a = "a" }); + local stanza = st.stanza("message", { type = "chat" }):text_tag("body", "Hello"); local stanza2 = st.preserialize(stanza); - assert.is_string(stanza2 and stanza.name, "preserialize returns a stanza"); + assert.is_table(stanza2, "Preserialized stanza is a table"); + assert.is_nil(getmetatable(stanza2), "Preserialized stanza has no metatable"); + assert.is_string(stanza2.name, "Preserialized stanza has a name field"); + assert.equal(stanza.name, stanza2.name, "Preserialized stanza has same name as the input stanza"); + assert.same(stanza.attr, stanza2.attr, "Preserialized stanza same attr table as input stanza"); assert.is_nil(stanza2.tags, "Preserialized stanza has no tag list"); assert.is_nil(stanza2.last_add, "Preserialized stanza has no last_add marker"); - assert.is_nil(getmetatable(stanza2), "Preserialized stanza has no metatable"); + assert.is_table(stanza2[1], "Preserialized child element preserved"); + assert.equal("body", stanza2[1].name, "Preserialized child element name preserved"); end); end); - describe("#preserialize()", function() + describe("#deserialize()", function() it("should work", function() - local stanza = st.stanza("message", { a = "a" }); + local stanza = { name = "message", attr = { type = "chat" }, { name = "body", attr = { }, "Hello" } }; local stanza2 = st.deserialize(st.preserialize(stanza)); - assert.is_string(stanza2 and stanza.name, "deserialize returns a stanza"); - assert.is_table(stanza2.attr, "Deserialized stanza has attributes"); - assert.are.equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes"); - assert.is_table(getmetatable(stanza2), "Deserialized stanza has metatable"); + + assert.is_table(stanza2, "Deserialized stanza is a table"); + assert.equal(st.stanza_mt, getmetatable(stanza2), "Deserialized stanza has stanza metatable"); + assert.is_string(stanza2.name, "Deserialized stanza has a name field"); + assert.equal(stanza.name, stanza2.name, "Deserialized stanza has same name as the input table"); + assert.same(stanza.attr, stanza2.attr, "Deserialized stanza same attr table as input table"); + assert.is_table(stanza2.tags, "Deserialized stanza has tag list"); + assert.is_table(stanza2[1], "Deserialized child element preserved"); + assert.equal("body", stanza2[1].name, "Deserialized child element name preserved"); end); end);
--- a/util/stanza.lua Sat Dec 01 22:13:24 2018 +0000 +++ b/util/stanza.lua Sun Dec 02 02:38:36 2018 +0100 @@ -361,41 +361,31 @@ stanza_mt.__freeze = preserialize; -local function deserialize(stanza) +local function deserialize(serialized) -- Set metatable - if stanza then - local attr = stanza.attr; - for i=1,#attr do attr[i] = nil; end + if serialized then + local attr = serialized.attr; local attrx = {}; - for att in pairs(attr) do - if s_find(att, "|", 1, true) and not s_find(att, "\1", 1, true) then - local ns,na = s_match(att, "^([^|]+)|(.+)$"); - attrx[ns.."\1"..na] = attr[att]; - attr[att] = nil; + for att, val in pairs(attr) do + if type(att) == "string" then + if s_find(att, "|", 1, true) and not s_find(att, "\1", 1, true) then + local ns,na = s_match(att, "^([^|]+)|(.+)$"); + attrx[ns.."\1"..na] = val; + else + attrx[att] = val; + end end end - for a,v in pairs(attrx) do - attr[a] = v; - end - setmetatable(stanza, stanza_mt); - for _, child in ipairs(stanza) do + local stanza = new_stanza(serialized.name, attrx); + for _, child in ipairs(serialized) do if type(child) == "table" then - deserialize(child); + stanza:add_direct_child(deserialize(child)); + elseif type(child) == "string" then + stanza:add_direct_child(child); end end - if not stanza.tags then - -- Rebuild tags - local tags = {}; - for _, child in ipairs(stanza) do - if type(child) == "table" then - t_insert(tags, child); - end - end - stanza.tags = tags; - end + return stanza; end - - return stanza; end local function _clone(stanza)