lua-users home
lua-l archive

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


On Aug 21, 2014, at 4:54 PM, Jonas Thiem <jonasthiem@googlemail.com> wrote:

> About the %p pattern... I still cannot judge if it is safe for all circumstances. 

Then find out by, for example, educating yourself about what that pattern means. 

Reading the documentation might help to get you started:

http://www.lua.org/manual/5.2/manual.html#6.4.1

• %p: represents all punctuation characters.

Then, find out what are all the 'magic characters’, in the same section of the documentation:

^$()%.[]*+-?

Then combine your first discovery, the ‘%p’ pattern, with the second one, the '^$()%.[]*+-? ‘ magic characters, and see how they interact for the purpose of escaping them:

print( ( '^$()%.[]*+-?' ):gsub( '%p', '%%%1' ) )

> %^%$%(%)%%%.%[%]%*%+%-%?

What is the above pattern doing? Are all the 'magic characters’ properly escaped? Are all the escape sequences valid? Is this all behaving properly as a ‘plain’  pattern, with no characters being considered magic? Any drawbacks? Any edge cases? Yes? No? Perhaps? Depend? 

You got plenty of test cases, right?

Don’t idly ‘judge’. Learn instead.