Skip to content

Commit fe7c73c

Browse files
fix: Add guard to date format to prevent invalid months (#1486)
* fix: Add guard to date format to prevent invalid months * again
1 parent 0157a3a commit fe7c73c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ export const index = await create_index(documents, assets, '../../../content', r
2323
const months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
2424

2525
function format_date(date: string) {
26+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
27+
throw new Error(`Invalid blog post date for date ${date}, should be in the format YYYY-MM-DD`);
28+
}
29+
2630
const [y, m, d] = date.split('-');
31+
const month = months[+m - 1];
32+
if (month === undefined) {
33+
throw new Error(`Invalid blog post month for date ${date}`);
34+
}
2735
return `${months[+m - 1]} ${+d} ${y}`;
2836
}
2937

0 commit comments

Comments
 (0)