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

fix: detect multiple zeros as an invalid step #743

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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