Skip to content

Commit 679e700

Browse files
committed
fix(after-hours): reject malformed schedule windows with extra segments
1 parent 628f6c1 commit 679e700

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

after-hours/schedule.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test('parseSchedule rejects bad input', () => {
1717
assert.throws(() => parseSchedule(JSON.stringify({ mon: '9:00-17:00' })), /HH:MM/i);
1818
assert.throws(() => parseSchedule(JSON.stringify({ mon: '17:00-09:00' })), /before close/i);
1919
assert.throws(() => parseSchedule(JSON.stringify({ mon: null, sun: null })), /no open days/i);
20+
assert.throws(() => parseSchedule(JSON.stringify({ mon: '09:00-17:00-junk' })), /HH:MM/i);
2021
});
2122

2223
test('parseSchedule yields minute windows and treats null/absent as closed', () => {

after-hours/schedule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export function parseSchedule(json: string): Schedule {
3737
if (!DAYS.includes(day)) throw new Error(`schedule: unknown day "${key}"`);
3838
if (value === null) continue; // closed
3939
if (typeof value !== 'string') throw new Error(`schedule: ${day} must be "HH:MM-HH:MM" or null`);
40-
const [openS, closeS] = value.split('-');
41-
const openMin = openS !== undefined ? parseHHMM(openS) : null;
42-
const closeMin = closeS !== undefined ? parseHHMM(closeS) : null;
40+
const m = /^(\d{2}:\d{2})-(\d{2}:\d{2})$/.exec(value);
41+
const openMin = m ? parseHHMM(m[1]) : null;
42+
const closeMin = m ? parseHHMM(m[2]) : null;
4343
if (openMin === null || closeMin === null) {
4444
throw new Error(`schedule: ${day} window "${value}" is not "HH:MM-HH:MM"`);
4545
}

0 commit comments

Comments
 (0)