gamesys / moonshine

A lightweight Lua VM for the browser
http://moonshinejs.org
MIT License
501 stars 35 forks source link

Pattern translator does not escape special characters correctly. #22

Open paulcuth opened 10 years ago

paulcuth commented 10 years ago

The following example highlights differences in output of pattern matching functions between C Lua and Moonshine.

print(string.gsub('ReturnRegionNotification', '\\u.?.?.?.?', 'XXX'))

C Lua returns:

ReturnRegionNotification    0

Moonshine returns:

RetXXXgionNotification  1

I believe there's some escaping of special chars missing from the translated pattern prior to construction of the RegExp object.

CerfurMark commented 10 years ago

I just ran into the same problem. Here are two examples:

s = "-" print(string.match(s, "%-")) output: userdata (should have been "-")

s = "-2" print(string.match(s, "%-%d")) output: 2 (should have been "-2")

The pattern matching seems to be having trouble with the minus sign. The %d seems to work ok.

These pattern matches work fine on my regular Lua.