util.stanza: Don't add xmlns to tags when serializing if same as the parent tag's xmlns. Should hopefully shut up Gajim once and for all :)

Sat, 17 Oct 2009 19:47:01 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 17 Oct 2009 19:47:01 +0100
changeset 1984
f2b1f89e1d7c
parent 1983
1f49d778bd98
child 1995
03ecc636af1e

util.stanza: Don't add xmlns to tags when serializing if same as the parent tag's xmlns. Should hopefully shut up Gajim once and for all :)

util/stanza.lua file | annotate | diff | comparison | revisions
--- a/util/stanza.lua	Sat Oct 17 18:09:07 2009 +0100
+++ b/util/stanza.lua	Sat Oct 17 19:47:01 2009 +0100
@@ -6,6 +6,7 @@
 -- COPYING file in the source package for more information.
 --
 
+
 local t_insert      =  table.insert;
 local t_concat      =  table.concat;
 local t_remove      =  table.remove;
@@ -130,7 +131,7 @@
 	_M.xml_escape = xml_escape;
 end
 
-local function _dostring(t, buf, self, xml_escape)
+local function _dostring(t, buf, self, xml_escape, parentns)
 	local nsid = 0;
 	local name = t.name
 	t_insert(buf, "<"..name);
@@ -139,7 +140,7 @@
 			local ns, attrk = s_match(k, "^([^|]+)|(.+)$");
 			nsid = nsid + 1;
 			t_insert(buf, " xmlns:ns"..nsid.."='"..xml_escape(ns).."' ".."ns"..nsid..":"..attrk.."='"..xml_escape(v).."'");
-		else
+               elseif not(k == "xmlns" and v == parentns) then
 			t_insert(buf, " "..k.."='"..xml_escape(v).."'");
 		end
 	end
@@ -151,7 +152,7 @@
 		for n=1,len do
 			local child = t[n];
 			if child.name then
-				self(child, buf, self, xml_escape);
+                               self(child, buf, self, xml_escape, t.attr.xmlns);
 			else
 				t_insert(buf, xml_escape(child));
 			end
@@ -161,7 +162,7 @@
 end
 function stanza_mt.__tostring(t)
 	local buf = {};
-	_dostring(t, buf, _dostring, xml_escape);
+       _dostring(t, buf, _dostring, xml_escape, nil);
 	return t_concat(buf);
 end
 

mercurial