[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bug: Literal strings in long format are not quite literal.
- From: Egor Skriptunoff <egor.skriptunoff@...>
- Date: Sat, 3 Nov 2012 01:11:51 +0300
On 11/2/12, Paul K <paulclinger@yahoo.com> wrote:
> This should work, but careful with newlines and EOF codes, as those
> may break your content. I used something like this in Serpent
> serializer:
> ("%q"):format(s):gsub("\010","n"):gsub("\026","\\026")
%q translates all control characters except '\n' into slashed form.
EOF char (ASCII 0x1A) will never appear in %q-formatted output.
0x0A encodes to backslash + LF, but even after newline
character modified it correctly decodes back to 0x0A,
as any combination backslash + LF/CRLF/CR/LFCR decodes into 0x0A.
IMHO, generated Lua code is safe even without these gsub-s.
And of course, png files should be treated as binary ("rb", "wb" modes)
to ignore magic of EOF chars.
Please show an example - how pure %q output may "break a content"?