Skip to content

Commit a538d1c

Browse files
committed
Fix crash on invalid dates
1 parent 71b30ca commit a538d1c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next
44
- Changed output to no longer be prettified.
55
- Fixed spacing issues resulting from output prettification.
6+
- Fixed a crash occurring when invalid dates are given to `#time`.
67
- Fixed underscores appearing in the default page title when present in the URL.
78
- Fixed links not being automatically capitalised.
89
- Fixed named references not working.

src/parse.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function parse(data: string, config: Config = {}): Result {
6969
// Images: [[File:Image.png|options|caption]]
7070
.replace(re(r`\[\[ (?:File|Image): (.*?) (\|.+?)? \]\]`), (_, file, params = '') => {
7171
if (params.includes('{{')) return _;
72+
if (params.includes('[[')) return _;
7273
if (!file) return '';
7374

7475
const path: string = paths.join(imagesFolder, file.trim().replace(/ /g, '_'));
@@ -249,7 +250,12 @@ export function parse(data: string, config: Config = {}): Result {
249250
const errMsg = `Wikity does not use Wikipedia's #time function syntax. Use repetition-based formatting (e.g. yyyy-mm-dd) instead.`;
250251
console.warn(`<Wikity> [WARN] ${errMsg}`);
251252
}
252-
return dateFormat(args[1] ? new Date(args[1]) : new Date(), args[0]);
253+
try {
254+
return dateFormat(args[1] ? new Date(args[1]) : new Date(), args[0]);
255+
}
256+
catch {
257+
return args[1] || args[0];
258+
}
253259
}
254260
})
255261

0 commit comments

Comments
 (0)