From e284edc00de9307c9ec89964c7e8076a526a6b70 Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Mon, 23 Oct 2023 16:08:38 +0200 Subject: [PATCH 1/3] test: add failing test for "00" cron step --- tests/crontime.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/crontime.test.ts b/tests/crontime.test.ts index 5954a215..1b050b58 100644 --- a/tests/crontime.test.ts +++ b/tests/crontime.test.ts @@ -213,6 +213,11 @@ describe('crontime', () => { expect(() => { new CronTime('* * * 1/0 *'); }).toThrow(); + + // infinite loop when providing two or more zeros as step (#742) + expect(() => { + new CronTime('* * * 1/00 *'); + }).toThrow(); }); it('should test invalid range', () => { From ab39ad4dc4954d2a8b472df6879675e30c7e04fa Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Mon, 23 Oct 2023 16:28:31 +0200 Subject: [PATCH 2/3] fix: prevent infinite loop if step is two or more zeros --- src/time.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/time.ts b/src/time.ts index 126698a1..81239a08 100644 --- a/src/time.ts +++ b/src/time.ts @@ -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`); From 9826bc1e36da8ac1e8e6a7e69b38dcd3c1e80f84 Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Wed, 25 Oct 2023 02:28:18 +0200 Subject: [PATCH 3/3] test: remove bad comment & add expect --- tests/crontime.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/crontime.test.ts b/tests/crontime.test.ts index 1b050b58..3827268b 100644 --- a/tests/crontime.test.ts +++ b/tests/crontime.test.ts @@ -210,11 +210,14 @@ describe('crontime', () => { }); it('should test invalid step', () => { + expect(() => { + new CronTime('* * * 1/ *'); + }).toThrow(); + expect(() => { new CronTime('* * * 1/0 *'); }).toThrow(); - // infinite loop when providing two or more zeros as step (#742) expect(() => { new CronTime('* * * 1/00 *'); }).toThrow();