From b9875e5501fe7ab32465e4677a9f35b064be5099 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 20:44:05 +0100 Subject: util.stanza: Check that argument to reply is a stanza --- spec/util_stanza_spec.lua | 6 ++++++ util/stanza.lua | 3 +++ 2 files changed, 9 insertions(+) diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 38503ab7..7d710888 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -170,6 +170,12 @@ describe("util.stanza", function() 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 --git a/util/stanza.lua b/util/stanza.lua index 55c38c73..f46d5b30 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -434,6 +434,9 @@ local function iq(attr) 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, -- cgit v1.2.3