From dfe21804fe9558ac19d2327d2cf4ed16267bc3fc Mon Sep 17 00:00:00 2001 From: matthew Date: Sun, 24 Aug 2008 14:52:02 +0000 Subject: Presence unavailable on disconnect --- util/stanza.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/stanza.lua b/util/stanza.lua index b4deda39..35277e9c 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -6,7 +6,7 @@ local setmetatable = setmetatable; local pairs = pairs; local ipairs = ipairs; local type = type; - +local s_gsub = string.gsub; module "stanza" stanza_mt = {}; @@ -78,10 +78,21 @@ function stanza_mt:childtags() end +do + local xml_entities = { ["'"] = "'", ["\""] = """, ["<"] = "<", [">"] = ">", ["&"] = "&" }; + function xml_escape(s) return s_gsub(s, "['&<>\"]", xml_entities); end +end + +local xml_escape = xml_escape; + function stanza_mt.__tostring(t) local children_text = ""; for n, child in ipairs(t) do - children_text = children_text .. tostring(child); + if type(child) == "string" then + children_text = children_text .. xml_escape(child); + else + children_text = children_text .. tostring(child); + end end local attr_string = ""; -- cgit v1.2.3