aboutsummaryrefslogtreecommitdiffstats
path: root/util/stanza.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-11-17 15:26:11 +0100
committerKim Alvefur <zash@zash.se>2018-11-17 15:26:11 +0100
commit50f63355017b033f4534f6012c796c7b5241a2d5 (patch)
tree2ee472e15e4b5e42a04ffa8b5afa7632065afbfd /util/stanza.lua
parent813f69fd2b4020313f5fc6de635523e681dafe38 (diff)
downloadprosody-50f63355017b033f4534f6012c796c7b5241a2d5.tar.gz
prosody-50f63355017b033f4534f6012c796c7b5241a2d5.zip
util.stanza: Validate input to clone() (with brief tests)
Diffstat (limited to 'util/stanza.lua')
-rw-r--r--util/stanza.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index 85c89d43..8d199912 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -398,7 +398,7 @@ local function deserialize(stanza)
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 @@ local function clone(stanza)
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 @@ local function clone(stanza)
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);