Skip to content

Commit aaf9914

Browse files
fix(json): improve ISO date string validation logic
1 parent e4ace79 commit aaf9914

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/operators/src/json/reviver.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ const isValidUrl = value =>
2020
isString(value) && URL.canParse(value) && /^[\w]+:\/\/\S+$/gm.test(value);
2121

2222
const isValidISODateString = value => {
23-
if (!isString(value) || !/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value)) return false;
24-
const d = new Date(value);
25-
return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === value; // valid date
23+
if (typeof value !== 'string' || value.trim() === '') {
24+
return false;
25+
}
26+
try {
27+
const d = new Date(value);
28+
return !Number.isNaN(d.valueOf()) && d.toISOString() === value;
29+
} catch {
30+
return false;
31+
}
2632
};
2733

2834
const isString = value => value?.constructor === String;

0 commit comments

Comments
 (0)