awful: check that text is not nil

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-04 16:21:12 +02:00
parent 9aa78f43e3
commit ac6093673d
1 changed files with 14 additions and 10 deletions

View File

@ -940,11 +940,13 @@ end
-- @param text Text to escape. -- @param text Text to escape.
-- @return Escape text. -- @return Escape text.
function escape(text) function escape(text)
text = text:gsub("&", "&amp;") if text then
text = text:gsub("<", "&lt;") text = text:gsub("&", "&amp;")
text = text:gsub(">", "&gt;") text = text:gsub("<", "&lt;")
text = text:gsub("'", "&apos;") text = text:gsub(">", "&gt;")
text = text:gsub("\"", "&quot;") text = text:gsub("'", "&apos;")
text = text:gsub("\"", "&quot;")
end
return text return text
end end
@ -952,11 +954,13 @@ end
-- @param text Text to unescape. -- @param text Text to unescape.
-- @return Unescaped text. -- @return Unescaped text.
function unescape(text) function unescape(text)
text = text:gsub("&amp;", "&") if text then
text = text:gsub("&lt;", "<") text = text:gsub("&amp;", "&")
text = text:gsub("&gt;", ">") text = text:gsub("&lt;", "<")
text = text:gsub("&apos;", "'") text = text:gsub("&gt;", ">")
text = text:gsub("&quot;", "\"") text = text:gsub("&apos;", "'")
text = text:gsub("&quot;", "\"")
end
return text return text
end end