[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [PATCH] lstrlib and match() \0 in pattern strings
- From: Rene Rebe <rene@...>
- Date: Mon, 29 Mar 2010 17:01:28 +0200
Hi Roberto,
what do yo think about incorporating something like my proposed patch to make a future lua version (like 5.2) string lib pattern matching embedded 0 aware? I'd really like the consistency and reliability, while the increase in code-size is very minimal.
Greetings,
René
On 12.03.2010, at 23:39, Rene Rebe wrote:
> Hi all,
>
> I was just drafting some code filtering arbitrary binary data input, relying on Lua strings to handle embedded zeros. While I had no problems with that in the past, I just spotted the pattern of the matching does treat the first \0 as the end of the pattern. I hope I did not over-read a subtile area of the Lua manual that points out embedded zeros are not allowed in the string library pattern matching so that those examples should work as I would expect:
>
> -- currently acts as if the pattern would be empty
> print (string.gsub("\0x\0", "\0", "_"))
>
> -- currently matches, although it shouldn't
> print (string.match("x", ".\0$"))
>
> Please find attached a quick review of the lstrlib. I hope I didn't miss a case. Passes the lua 5.1 test-suite (in normal mode, without the lua core test patch).
>
> <lstrlib-0s.patch>
>
> PS: Applies to lua 5.2-work2 with minimal whitespace fixup, likewise.
>
> René
>
> --
> René Rebe, ExactCODE GmbH, Jaegerstr. 67, DE-10117 Berlin
> http://exactcode.com | http://t2-project.org | http://rene.rebe.de
>
--
René Rebe, ExactCODE GmbH, Jaegerstr. 67, DE-10117 Berlin
http://exactcode.com | http://t2-project.org | http://rene.rebe.de