Skip to content

Commit

Permalink
fix: detect multiple zeros as an invalid step (#743) [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox authored Oct 25, 2023
1 parent 5ff1cf8 commit b0bf677
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,10 @@ export class CronTime {
let upper = mUpper !== undefined ? parseInt(mUpper, 10) : undefined;

const wasStepDefined = mStep !== undefined;
if (mStep === '0') {
const step = parseInt(mStep ?? '1', 10);
if (step === 0) {
throw new Error(`Field (${unit}) has a step of zero`);
}
const step = parseInt(mStep ?? '1', 10);

if (upper !== undefined && lower > upper) {
throw new Error(`Field (${unit}) has an invalid range`);
Expand Down
8 changes: 8 additions & 0 deletions tests/crontime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,17 @@ describe('crontime', () => {
});

it('should test invalid step', () => {
expect(() => {
new CronTime('* * * 1/ *');
}).toThrow();

expect(() => {
new CronTime('* * * 1/0 *');
}).toThrow();

expect(() => {
new CronTime('* * * 1/00 *');
}).toThrow();
});

it('should test invalid range', () => {
Expand Down

0 comments on commit b0bf677

Please sign in to comment.