Merge 0.9->0.10
[prosody.git] / util / stanza.lua
index 82601e630986fc4376f22c714144bba267b27212..3d7caf8c5bff1582d1888f25d166edc03ec76d67 100644 (file)
@@ -202,8 +202,19 @@ end
 
 local xml_escape
 do
-       local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };
-       function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end
+       local escape_table = {
+               ["'"] = "&apos;";
+               ['"'] = "&quot;";
+               ["<"] = "&lt;";
+               [">"] = "&gt;";
+               ["&"] = "&amp;";
+               -- escape this whitespace because [\r\n\t] change into spaces in attributes
+               -- and \r\n changes into \n in text, and we want to preserve original bytes
+               ["\t"] = "&#x9;";
+               ["\n"] = "&#xA;";
+               ["\r"] = "&#xD;";
+       };
+       function xml_escape(str) return (s_gsub(str, "['&<>\"\t\n\r]", escape_table)); end
        _M.xml_escape = xml_escape;
 end