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

convertSteps function miss cases of a string as a divider #226

Closed
ZimGil opened this issue May 18, 2020 · 0 comments · Fixed by #227
Closed

convertSteps function miss cases of a string as a divider #226

ZimGil opened this issue May 18, 2020 · 0 comments · Fixed by #227

Comments

@ZimGil
Copy link
Contributor

ZimGil commented May 18, 2020

I ran into a case where I passed an undefined value as part of my expression as */undefined * * * * and cron.validate() return true and find that it behave the same as a normal * * * * *

If I understand correctly, in this case the convertSteps function should receive 1,2,3,4,5,...,59/undefined which is not getting picked up by the ^(.+)\/(\d+)$ regex.

function convertSteps(expressions){
var stepValuePattern = /^(.+)\/(\d+)$/;
for(var i = 0; i < expressions.length; i++){
var match = stepValuePattern.exec(expressions[i]);
var isStepValue = match !== null && match.length > 0;
if(isStepValue){
var values = match[1].split(',');
var setpValues = [];
var divider = parseInt(match[2], 10);
for(var j = 0; j <= values.length; j++){

Later it gets to the normalizeIntegers function and: parseInt('59/undefined') => 59

Proposed Solution:
We can change the regex to ^(.+)\/(\w+)$ and check as early as possible if isNaN(divider) and throw an error in other cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant