# HG changeset patch # User Kim Alvefur # Date 1574711045 -3600 # Node ID 22db763c510cdc0a75a8e8c18a167cc91109a0b0 # Parent f2c9abc71f08750fc61659331b5ac9aada0edbc6 util.stanza: Check that argument to reply is a stanza diff -r f2c9abc71f08 -r 22db763c510c spec/util_stanza_spec.lua --- 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() diff -r f2c9abc71f08 -r 22db763c510c util/stanza.lua --- 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,