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 2 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
5 changes: 5 additions & 0 deletions tests/crontime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ describe('crontime', () => {
expect(() => {
new CronTime('* * * 1/0 *');
}).toThrow();

// infinite loop when providing two or more zeros as step (#742)
intcreator marked this conversation as resolved.
Show resolved Hide resolved
expect(() => {
new CronTime('* * * 1/00 *');
}).toThrow();
});

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