Changeset

10442:22db763c510c

util.stanza: Check that argument to reply is a stanza
author Kim Alvefur <zash@zash.se>
date Mon, 25 Nov 2019 20:44:05 +0100
parents 10441:f2c9abc71f08
children 10443:f28718f46196
files spec/util_stanza_spec.lua util/stanza.lua
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua	Sun Nov 24 04:46:36 2019 +0100
+++ b/spec/util_stanza_spec.lua	Mon Nov 25 20:44:05 2019 +0100
@@ -170,6 +170,12 @@
 			assert.are.equal(r.attr.type, "result");
 			assert.are.equal(#r.tags, 0, "A reply should not include children of the original stanza");
 		end);
+
+		it("should reject not-stanzas", function ()
+			assert.has.error_match(function ()
+				st.reply(not "a stanza");
+			end, "expected stanza");
+		end);
 	end);
 
 	describe("#error_reply()", function()
--- a/util/stanza.lua	Sun Nov 24 04:46:36 2019 +0100
+++ b/util/stanza.lua	Mon Nov 25 20:44:05 2019 +0100
@@ -434,6 +434,9 @@
 end
 
 local function reply(orig)
+	if not is_stanza(orig) then
+		error("bad argument to reply: expected stanza, got "..type(orig));
+	end
 	return new_stanza(orig.name,
 		orig.attr and {
 			to = orig.attr.from,