Skip to content

Commit f9fa8f8

Browse files
fix: Add guard to date format to prevent invalid months
1 parent 800d171 commit f9fa8f8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

apps/svelte.dev/src/lib/server/content.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
2424

2525
function format_date(date: string) {
2626
const [y, m, d] = date.split('-');
27+
const month = months[+m - 1];
28+
if (month === undefined) {
29+
throw new Error(`Invalid blog post month for date ${date}`);
30+
}
2731
return `${months[+m - 1]} ${+d} ${y}`;
2832
}
2933

0 commit comments

Comments
 (0)