no infinite loop on non global regex
This commit is contained in:
@ -45,9 +45,30 @@ test ('run regex', (t) => {
|
||||
const data = 'foobarfoo';
|
||||
const regex = /foo/gu;
|
||||
let count = 0;
|
||||
util.run_regex(regex,data,(res)=>{
|
||||
t.is(res[0], 'foo');
|
||||
util.run_regex (regex, data, (res) => {
|
||||
t.is (res[0], 'foo');
|
||||
count++;
|
||||
})
|
||||
t.is(count, 2);
|
||||
});
|
||||
t.is (count, 2);
|
||||
});
|
||||
|
||||
test ('run non-global regex', (t) => {
|
||||
const data = 'foobarfoo';
|
||||
const regex = /foo/u;
|
||||
let count = 0;
|
||||
util.run_regex (regex, data, (res) => {
|
||||
t.is (res[0], 'foo');
|
||||
count++;
|
||||
});
|
||||
t.is (count, 1);
|
||||
});
|
||||
|
||||
test ('run non-global regex without result', (t) => {
|
||||
const data = 'foobarfoo';
|
||||
const regex = /baz/u;
|
||||
let count = 0;
|
||||
util.run_regex (regex, data, (res) => {
|
||||
count++;
|
||||
});
|
||||
t.is (count, 0);
|
||||
});
|
||||
|
Reference in New Issue
Block a user