Skip to content

Commit

Permalink
SED-3140 fix cron validator to accept all valid expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
dvladir authored May 23, 2024
1 parent 5ddbb13 commit eb266d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export class CronValidatorsFactory {
new NoSpecificValidator(
new LWValidator(
new ArrayValidator(
new MultipleValidator(new IncrementValidator(this.daysOfMonths), new RangeValidator(this.daysOfMonths))
new MultipleValidator(
new IncrementValidator(new RangeValidator(this.daysOfMonths)),
new RangeValidator(this.daysOfMonths)
)
)
)
)
Expand All @@ -53,7 +56,7 @@ export class CronValidatorsFactory {
new LWValidator(
new ArrayValidator(
new MultipleValidator(
new IncrementValidator(this.weekDays),
new IncrementValidator(new RangeValidator(this.weekDays)),
new RangeValidator(this.weekDays),
new NextDayValidator(this.weekDays)
)
Expand All @@ -69,7 +72,9 @@ export class CronValidatorsFactory {

private createValidatorWithCommonRules(validator: BaseCronValidator): BaseCronValidator {
return new AllValidator(
new ArrayValidator(new MultipleValidator(new IncrementValidator(validator), new RangeValidator(validator)))
new ArrayValidator(
new MultipleValidator(new IncrementValidator(new RangeValidator(validator)), new RangeValidator(validator))
)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { BaseCronValidator } from './_base-cron-validator';

const REGEX_NUM = /^\d+$/;

export class IncrementValidator extends BaseCronValidator {
override validate(source: unknown): boolean {
if (typeof source !== 'string' || !source.includes('/')) {
Expand All @@ -19,7 +21,7 @@ export class IncrementValidator extends BaseCronValidator {
return false;
}

if (isNaN(parseInt(parts[1])) || parseInt(parts[1]) <= 0) {
if (!REGEX_NUM.test(parts[1]) || parseInt(parts[1]) <= 0) {
return false;
}

Expand Down

0 comments on commit eb266d5

Please sign in to comment.