Closed Nioub closed 11 years ago
Thanks for notifying me about this issue.
The problem is that if a cached RegExp
contains a set global flag g
, then the lastIndex
property on the object will only reset to 0 when a failed match has occurred for .exec()
or .test()
.
However, this isn't a problem with Ratio.js because there isn't an RegExp objects that uses the global flag g
.
If there was one, then I would have to create a new RegExp
every time the function was called.
More info here: http://www.tutorialspoint.com/javascript/regexp_lastindex.htm
Thanks for the insight. I did not realized this was caused by the g
flag. I'll check my codebases for misuses of this flag.
I haven't properly analyzed yet, but I think there may be a bug with
Ratio.regex
if these regexes are being reused, theirlastIndex
property is not being reset to 0 in subsequenttest()
calls (see http://stackoverflow.com/questions/1534098/regex-lastindex-unexpected-behaviour). This can be fixed easily for example by manually reseting before use: