GuillaumeRochat/cron-validator

Zero frequency `/0` scenario should be invalid

kaushalnavneet opened this issue · 2 comments

This issue is caught in a Timed Trigger type for a Tekton pipeline.
The cron-validator library, that we use to validate the cron expression, is not able to validate a zero frequency scenario. When we call cron.isValidCron(...) it should return false when a divide by 0 expression is included.
(Expression examples: 0/0 9 8 * *, 0 9 8 * */0, 0 9 8/0 * *, etc)

Below code is used for the validation:

import cronParser from "cron-parser";
const cron = require("cron-validator");
...
cron.isValidCron(cronString, { alias: true });
...
const cronObj = cronParser.parseExpression(cronString, { utc: true });

Expected Result:
cron.isValidCron(...) should return false for any expression that has zero frequency (/0 divide by zero component).
Actual Result:
cron.isValidCron(...) is not returning in the said scenario whereas cronParser.parseExpression(...) throws error Error: Constraint error, cannot repeat at every 0 time.

Oh wow... I left a divide by 0 in there. I quickly fixed it on 1.2.1 if you want to try the fix.

Thank you, @GuillaumeRochat, the fix worked.