# HG changeset patch # User Kim Alvefur <zash@zash.se> # Date 1542466112 -3600 # Node ID 28be90eb774ad4fc4a319050b5a6cd0537a1395f # Parent b7a23136f345bdd9444c36c378a284734dc8bd02# Parent fdefc43bffffd6dbeda9e36161e6fbc5aaa6f229 Merge 0.11->trunk diff -r b7a23136f345 -r 28be90eb774a plugins/mod_csi_simple.lua --- a/plugins/mod_csi_simple.lua Thu Nov 15 21:55:32 2018 +0000 +++ b/plugins/mod_csi_simple.lua Sat Nov 17 15:48:32 2018 +0100 @@ -48,6 +48,9 @@ module:hook("csi-is-stanza-important", function (event) local stanza = event.stanza; + if not st.is_stanza(stanza) then + return true; + end local st_name = stanza.name; if not st_name then return false; end local st_type = stanza.attr.type; @@ -82,8 +85,10 @@ pump:flush(); send(stanza); else - stanza = st.clone(stanza); - stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = bare_jid, stamp = dt.datetime()})); + if st.is_stanza(stanza) then + stanza = st.clone(stanza); + stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = bare_jid, stamp = dt.datetime()})); + end pump:push(stanza); end return true; diff -r b7a23136f345 -r 28be90eb774a spec/util_stanza_spec.lua --- a/spec/util_stanza_spec.lua Thu Nov 15 21:55:32 2018 +0000 +++ b/spec/util_stanza_spec.lua Sat Nov 17 15:48:32 2018 +0100 @@ -346,4 +346,18 @@ end, "Invalid stanza"); end); end); + + describe("#clone", function () + it("works", function () + local s = st.message({type="chat"}, "Hello"):reset(); + local c = st.clone(s); + assert.same(s, c); + end); + + it("works", function () + assert.has_error(function () + st.clone("this is not a stanza"); + end); + end); + end); end); diff -r b7a23136f345 -r 28be90eb774a util/stanza.lua --- a/util/stanza.lua Thu Nov 15 21:55:32 2018 +0000 +++ b/util/stanza.lua Sat Nov 17 15:48:32 2018 +0100 @@ -398,7 +398,7 @@ return stanza; end -local function clone(stanza) +local function _clone(stanza) local attr, tags = {}, {}; for k,v in pairs(stanza.attr) do attr[k] = v; end local old_namespaces, namespaces = stanza.namespaces; @@ -410,7 +410,7 @@ for i=1,#stanza do local child = stanza[i]; if child.name then - child = clone(child); + child = _clone(child); t_insert(tags, child); end t_insert(new, child); @@ -418,6 +418,13 @@ return setmetatable(new, stanza_mt); end +local function clone(stanza) + if not is_stanza(stanza) then + error("bad argument to clone: expected stanza, got "..type(stanza)); + end + return _clone(stanza); +end + local function message(attr, body) if not body then return new_stanza("message", attr);