Software /
code /
prosody
Diff
util/stanza.lua @ 4:09c3845ed442
Presence unavailable on disconnect
author | matthew |
---|---|
date | Sun, 24 Aug 2008 14:52:02 +0000 |
parent | 2:9bb397205f26 |
child | 6:7ad47ce20394 |
line wrap: on
line diff
--- a/util/stanza.lua Sun Aug 24 13:29:01 2008 +0000 +++ b/util/stanza.lua Sun Aug 24 14:52:02 2008 +0000 @@ -6,7 +6,7 @@ local pairs = pairs; local ipairs = ipairs; local type = type; - +local s_gsub = string.gsub; module "stanza" stanza_mt = {}; @@ -78,10 +78,21 @@ 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 = "";