Rewrite of the escape helper.

It is simillar to the awful.util.escape now, using a table which we
could expand (and rename) with other unwated characters if it comes to
that. I saw awesome break on many occasions because of encoding
problems.
This commit is contained in:
Adrian C. (anrxc) 2009-08-03 04:29:06 +02:00
parent 047dba0e5d
commit 09fda0ab05
1 changed files with 13 additions and 13 deletions

View File

@ -101,15 +101,15 @@ end
--{{{ Escape a string
function escape(text)
if text then
text = text:gsub("&", "&")
text = text:gsub("<", "&lt;")
text = text:gsub(">", "&gt;")
text = text:gsub("'", "&apos;")
text = text:gsub("\"", "&quot;")
end
local xml_entities = {
["\""] = "&quot;",
["&"] = "&amp;",
["'"] = "&apos;",
["<"] = "&lt;",
[">"] = "&gt;"
}
return text
return text and text:gsub("[\"&'<>]", xml_entities)
end
-- }}}
-- }}}