Making the best attempt out of a bad merge from waqas
[prosody.git] / util / stanza.lua
index a4fd0f82ad698557eee3fa61276a4f06eac7902f..6bc70ab91d8cb609e0392b6c69371fc564c977d0 100644 (file)
@@ -122,21 +122,23 @@ end
 
 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
+               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
-               stanza.tags = tags;
        end
        
        return stanza;