You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I ran into this issue while scheduling a task to run every X minutes between the hours of 0-2,10-23
It showed sporadic behavior, working sometimes but not other times. The issue is in the range conversion file. I have a fix for it and Ill open a PR, just wanted to post this issue for documentation purposes. Below is a snippet of some code taken from range-conversion (I modified it a bit to show where the issue arises.)
function replaceWithRange(expression, text, init, end) {
var numbers = [];
var last = parseInt(end);
var first = parseInt(init);
console.log(`first ${first}`)
console.log(`last ${last}`)
if (first > last) {
last = parseInt(init);
first = parseInt(end);
}
for (var i = first; i <= last; i++) {
numbers.push(i);
}
console.log(`numbers ${numbers}`)
console.log(`expression before actual replace ${expression}`)
console.log(`expression after ${expression.replace(new RegExp(text, 'gi'), numbers.join())}`)
return expression.replace(new RegExp(text, 'gi'), numbers.join());
}
function convertRange(expression) {
console.log(`expression ${expression}`)
var rangeRegEx = /(^\d+)\-(\d+)/;
var match = rangeRegEx.exec(expression);
console.log(`match ${match}`)
console.log(`expression after exec ${expression}`)
while (match !== null && match.length > 0) {
console.log(`replaceWithRange(${expression}, ${match[0]}, ${match[1]}, ${match[2]})`)
expression = replaceWithRange(expression, match[0], match[1], match[2]);
console.log(`expression after replace ${expression}`)
match = rangeRegEx.exec(expression);
}
console.log(`expression final ${expression}`)
console.log(' ')
return expression;
}
console.log(`Original: 0-2,10-23`)
console.log(` `)
console.log(`Final: ${convertRange('0-2,10-23')}`)
Heres the output:
Original: 0-2,10-23
expression 0-2,10-23
match 0-2,0,2
expression after exec 0-2,10-23
replaceWithRange(0-2,10-23, 0-2, 0, 2)
first 0
last 2
numbers 0,1,2
expression before actual replace 0-2,10-23
expression after 0,1,2,10,1,23
expression after replace 0,1,2,10,1,23
expression final 0,1,2,10,1,23
Final: 0,1,2,10,1,23
You can see the output seems to not parse the second range correctly. It seems the replace function uses the g (global) option to replace the original expression everywhere its found. In our case, the original 0-2 also appears in 10-23 ( 1[0-2]3 ) and the next time the loop run, it dosen't find anything that needs to be replaced.
The text was updated successfully, but these errors were encountered:
Hello, I ran into this issue while scheduling a task to run every X minutes between the hours of 0-2,10-23
It showed sporadic behavior, working sometimes but not other times. The issue is in the range conversion file. I have a fix for it and Ill open a PR, just wanted to post this issue for documentation purposes. Below is a snippet of some code taken from range-conversion (I modified it a bit to show where the issue arises.)
Heres the output:
You can see the output seems to not parse the second range correctly. It seems the replace function uses the g (global) option to replace the original expression everywhere its found. In our case, the original 0-2 also appears in 10-23 ( 1[0-2]3 ) and the next time the loop run, it dosen't find anything that needs to be replaced.
The text was updated successfully, but these errors were encountered: