Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ snapshot[`round trip - URL {\\n href: 'https://fresh.deno.dev/',\\n origin: 'h

snapshot[`round trip - 1990-05-31T00:00:00.000Z 1`] = `'[["Date","1990-05-31T00:00:00.000Z"]]'`;

snapshot[`round trip - Invalid Date 1`] = `'[["Date","Invalid Date"]]'`;

snapshot[`round trip - Map(2) { 1 => null, undefined => -2 } 1`] = `'[["Map",[1,-2,-1,2]],1,-2]'`;

snapshot[`round trip - Set(5) { 1, 2, null, -2, NaN } 1`] = `'[["Set",[1,2,-2,3,-3]],1,2,-2]'`;
Expand Down
1 change: 1 addition & 0 deletions packages/fresh/src/jsonify/round_trip_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const TESTS = [
new Uint8Array([1, 2, 3]),
new URL("https://fresh.deno.dev"),
new Date("1990-05-31"),
new Date("Invalid Date"),
new Map([[1, null], [undefined, -2]]),
new Set([1, 2, null, -2, NaN]),
[1, , 3],
Expand Down
8 changes: 7 additions & 1 deletion packages/fresh/src/jsonify/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ function serializeInner(
if (value instanceof URL) {
str += `["URL","${value.href}"]`;
} else if (value instanceof Date) {
str += `["Date","${value.toISOString()}"]`;
let iso: string;
try {
iso = value.toISOString();
} catch {
iso = "Invalid Date";
}
str += `["Date","${iso}"]`;
} else if (value instanceof RegExp) {
str += `["RegExp",${JSON.stringify(value.source)}, "${value.flags}"]`;
} else if (value instanceof Uint8Array) {
Expand Down
Loading