lua-users home
lua-l archive

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


On Sat, Apr 4, 2009 at 11:12 PM, Francio <francio@francio.pl> wrote:
> Hello!
>
<snip>
> And by the way, is this way of concatenating 100% safe of any code
> injections? Can only "]]" end string beginning with "[["?
>

There is no 100% safe way the way you are doing it - whatever you use
for the start have an end marker, and there is always a chance that
this end marker will appear in the user's code.

The correct way is using string.format()'s %q specifier:

Your example would be:
"user_code= " .. string.format("%q", user_code_here) .. "]]"

or better:
string.format("user_code = %q", user_code_here)

Hope this helps.