Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional/pattern.js: Don't use exec() or test() here #2199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

s-belichenko
Copy link

In some cases, this code will not work correctly. Calling these methods on the same RegExp, will start checking from the end of the previous comparison.

Just try to run this code:

var regex1 = RegExp('foo*');
var regex2 = RegExp('foo*','g');
var str1 = 'table football';

console.log(regex1.exec(str1));
console.log(regex1.exec(str1));
console.log(regex2.exec(str1));
console.log(regex2.exec(str1));
console.log(regex2.exec(str1));
console.log('==============');
console.log(str1.match(regex1));
console.log(str1.match(regex1));
console.log(str1.match(regex2));
console.log(str1.match(regex2));
console.log(str1.match(regex2));

Result:

Array ["foo"]
Array ["foo"]
Array ["foo"]
null
Array ["foo"]
"=============="
Array ["foo"]
Array ["foo"]
Array ["foo"]
Array ["foo"]
Array ["foo"]

@s-belichenko s-belichenko changed the title Don't use exec() or test() here additional/pattern.js: Don't use exec() or test() here Aug 13, 2018
In some cases, this code will not work correctly. Calling these methods on the same RegExp, will start checking from the end of the previous comparison.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants