Skip to content

Commit 8e27c04

Browse files
feat: enhance CronValidationService to restrict multiple hash expressions in day-of-week field
1 parent 9b93ebd commit 8e27c04

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

projects/cps-ui-kit/src/lib/services/cron-validation.service.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ describe('CronValidationService', () => {
200200
expect(service.isValidCron('0 9 ? * MON#0 *')).toBe(false); // Week 0 invalid
201201
expect(service.isValidCron('0 9 ? * MON#6 *')).toBe(false); // Week 6 invalid
202202
expect(service.isValidCron('0 9 15#1 * ? *')).toBe(false); // Hash in day-of-month
203+
expect(service.isValidCron('0 9 ? * SUN#5,MON#4 *')).toBe(false); // two expressions with a hash for day-of-week field should not be allowed
203204
});
204205
});
205206
});

projects/cps-ui-kit/src/lib/services/cron-validation.service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Injectable } from '@angular/core';
1515
* - Steps: asterisk/15, 5/10, 1-5/2
1616
* - Lists: 1,3,5, MON,WED,FRI
1717
* - Special chars: L (last), W (weekday), hash (nth occurrence)
18+
* @see {@link https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html#cron-based | AWS EventBridge Scheduler - Cron-based schedules}
1819
*/
1920
@Injectable({
2021
providedIn: 'root'
@@ -409,6 +410,19 @@ export class CronValidationService {
409410
* Validates day-of-week field with support for named days and special characters.
410411
*/
411412
private validateDayOfWeek(dayOfWeek: string): boolean {
413+
// Check for multiple hash expressions in day-of-week field
414+
if (dayOfWeek.includes(',') && dayOfWeek.includes('#')) {
415+
const parts = dayOfWeek.split(',');
416+
const hashCount = parts.filter((part) =>
417+
part.trim().includes('#')
418+
).length;
419+
420+
// AWS EventBridge: Only one hash expression allowed per day-of-week field
421+
if (hashCount > 1) {
422+
return false;
423+
}
424+
}
425+
412426
return this.validateComplexField(dayOfWeek, 1, 7, 'dayOfWeek');
413427
}
414428

0 commit comments

Comments
 (0)