fix: reject impossible weekly automation schedules (#4205)

This commit is contained in:
Neil 2026-05-31 08:14:43 -07:00 committed by GitHub
parent 0e645692b4
commit 0474f4e855
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -81,6 +81,19 @@ describe('automation schedules', () => {
expect(tryParseAutomationRrule('FREQ=WEEKLY;BYDAY=MO,NO;BYHOUR=10;BYMINUTE=15')).toBeNull()
})
it('rejects weekly RRULE schedules that cannot match any day', () => {
const rrule = 'FREQ=WEEKLY;BYHOUR=9;BYMINUTE=0'
expect(isValidAutomationSchedule(rrule)).toBe(false)
expect(() =>
nextAutomationOccurrenceAfter(
rrule,
new Date('2026-05-01T00:00:00').getTime(),
new Date('2026-05-02T00:00:00').getTime()
)
).toThrow('Invalid recurrence day.')
})
it('formats invalid schedules with a safe fallback label', () => {
expect(formatAutomationSchedule('FREQ=YEARLY')).toBe('Invalid schedule')
})

View File

@ -86,6 +86,13 @@ function parseRrule(rrule: string): ParsedRrule {
throw new Error('Invalid recurrence minute.')
}
const byDay = (entries.get('BYDAY') ?? '').split(',').filter(Boolean)
if (
freq === 'WEEKLY' &&
(byDay.length === 0 ||
byDay.some((day) => !DAY_CODES.includes(day as (typeof DAY_CODES)[number])))
) {
throw new Error('Invalid recurrence day.')
}
return { kind: 'rrule', freq, byDay, byHour, byMinute }
}