Skip to content

Instantly share code, notes, and snippets.

@zeen
Created October 4, 2009 18:04
Show Gist options
  • Save zeen/201524 to your computer and use it in GitHub Desktop.
Save zeen/201524 to your computer and use it in GitHub Desktop.
diff -r 93a94ec05ebe util/stanza.lua
--- a/util/stanza.lua Sun Oct 04 22:12:12 2009 +0500
+++ b/util/stanza.lua Sun Oct 04 23:07:05 2009 +0500
@@ -122,7 +122,7 @@
local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };
return function(str) return (s_gsub(str, "['&<>\"]", escape_table)); end
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);
@@ -131,7 +131,7 @@
local ns, attrk = s_match(k, "^([^|]+)|(.+)$");
nsid = nsid + 1;
t_insert(buf, " xmlns:ns"..nsid.."='"..xml_escape(ns).."' ".."ns"..nsid..":"..attrk.."='"..xml_e
scape(v).."'");
- else
+ elseif not(k == "xmlns" and v == parentns) then
t_insert(buf, " "..k.."='"..xml_escape(v).."'");
end
end
@@ -143,7 +143,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
@@ -153,7 +153,7 @@
end
function stanza_mt.__tostring(t)
local buf = {};
- _dostring(t, buf, _dostring, xml_escape);
+ _dostring(t, buf, _dostring, xml_escape, "jabber:client");
return t_concat(buf);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment