lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


This variant takes care of those cases quite neatly, while preserving
ease of use for most cases.

function escape(s) return "[[" .. s:gsub("%]%]", "]]..']]'..[[") .. "]]" end

On Thu, Feb 21, 2008 at 6:49 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
> > I guess I don't consider that a use case for s:format("%q") but rather a
>  > use case for io.write('[[' .. s .. ']]').
>
>  If s comes from user input, then this is unsafe if later loaded back into Lua:
>  s might be "]]; MALICIOUS CODE HERE ; [[" or something like that.
>