lua-users home
lua-l archive

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


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).

Attachment: lstrlib-0s.patch
Description: Binary data


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