util.stanza: Allow :text(nil) and :text("") as harmless nops
authorMatthew Wild <mwild1@gmail.com>
Wed, 21 Mar 2018 22:04:20 +0000
changeset 8643 8f13ec2ceb06
parent 8642 070a77c15f63
child 8644 c7734b59506f
util.stanza: Allow :text(nil) and :text("") as harmless nops
util/stanza.lua
--- a/util/stanza.lua	Wed Mar 21 16:31:48 2018 +0100
+++ b/util/stanza.lua	Wed Mar 21 22:04:20 2018 +0000
@@ -111,9 +111,11 @@
 end
 
 function stanza_mt:text(text)
-	check_text(text, "text");
-	local last_add = self.last_add;
-	(last_add and last_add[#last_add] or self):add_direct_child(text);
+	if text ~= nil and text ~= "" then
+		check_text(text, "text");
+		local last_add = self.last_add;
+		(last_add and last_add[#last_add] or self):add_direct_child(text);
+	end
 	return self;
 end