jbe/bsw@0: --[[-- jbe/bsw@0: result = -- encoded string jbe/bsw@0: encode.html( jbe/bsw@0: str -- original string jbe/bsw@0: ) jbe/bsw@0: jbe/bsw@0: This function replaces the special characters '<', '>', '&' and '"' by their HTML entities '<', '&rt;', '&' and '"'. jbe/bsw@0: jbe/bsw@0: NOTE: ACCELERATED FUNCTION jbe/bsw@0: Do not change unless also you also update webmcp_accelerator.c jbe/bsw@0: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function encode.html(text) jbe/bsw@0: -- TODO: perhaps filter evil control characters? jbe/bsw@0: return ( jbe/bsw@0: string.gsub( jbe/bsw@0: text, '[<>&"]', jbe/bsw@0: function(char) jbe/bsw@0: if char == '<' then jbe/bsw@0: return "<" jbe/bsw@0: elseif char == '>' then jbe/bsw@0: return ">" jbe/bsw@0: elseif char == '&' then jbe/bsw@0: return "&" jbe/bsw@0: elseif char == '"' then jbe/bsw@0: return """ jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: ) jbe/bsw@0: ) jbe/bsw@0: end