Fixed: util.stanza.deserialize now handles nil stanzas

Thu, 09 Oct 2008 22:19:35 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Thu, 09 Oct 2008 22:19:35 +0500
changeset 91
6d66eb6b24cb
parent 90
da468ed49a7b
child 92
0261260cf9a7

Fixed: util.stanza.deserialize now handles nil stanzas

util/stanza.lua file | annotate | diff | comparison | revisions
--- a/util/stanza.lua	Thu Oct 09 00:50:45 2008 +0100
+++ b/util/stanza.lua	Thu Oct 09 22:19:35 2008 +0500
@@ -122,21 +122,23 @@
 
 function deserialize(stanza)
 	-- Set metatable
-	setmetatable(stanza, stanza_mt);
-	for _, child in ipairs(stanza) do
-		if type(child) == "table" then
-			deserialize(child);
-		end
-	end
-	if not stanza.tags then
-		-- Rebuild tags
-		local tags = {};
+	if stanza then
+		setmetatable(stanza, stanza_mt);
 		for _, child in ipairs(stanza) do
 			if type(child) == "table" then
-				t_insert(tags, child);
+				deserialize(child);
 			end
 		end
-		stanza.tags = tags;
+		if not stanza.tags then
+			-- Rebuild tags
+			local tags = {};
+			for _, child in ipairs(stanza) do
+				if type(child) == "table" then
+					t_insert(tags, child);
+				end
+			end
+			stanza.tags = tags;
+		end
 	end
 	
 	return stanza;

mercurial