webmcp

view framework/env/encode/html.lua @ 262:c3d539e33710

Replaced request.add_initializer(...) and request.add_variable(...) with request.for_each(...) and request.configure(...) which both execute the passed function once in any case when being called
author jbe
date Tue Mar 17 11:42:34 2015 +0100 (2015-03-17)
parents 9fdfb27f8e67
children
line source
1 --[[--
2 result = -- encoded string
3 encode.html(
4 str -- original string
5 )
7 This function replaces the special characters '<', '>', '&' and '"' by their HTML entities '&lt;', '&rt;', '&amp;' and '&quot;'.
9 NOTE: ACCELERATED FUNCTION
10 Do not change unless also you also update webmcp_accelerator.c
12 --]]--
14 function encode.html(text)
15 -- TODO: perhaps filter evil control characters?
16 return (
17 string.gsub(
18 text, '[<>&"]',
19 function(char)
20 if char == '<' then
21 return "&lt;"
22 elseif char == '>' then
23 return "&gt;"
24 elseif char == '&' then
25 return "&amp;"
26 elseif char == '"' then
27 return "&quot;"
28 end
29 end
30 )
31 )
32 end

Impressum / About Us