mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Reject ridiculous years in Gantt charts.
This commit is contained in:
parent
c79be5d829
commit
725b80831e
@ -287,7 +287,17 @@ const getStartDate = function (prevTime, dateFormat, str) {
|
||||
log.debug('Invalid date:' + str);
|
||||
log.debug('With date format:' + dateFormat.trim());
|
||||
const d = new Date(str);
|
||||
if (d === undefined || isNaN(d.getTime())) {
|
||||
if (
|
||||
d === undefined ||
|
||||
isNaN(d.getTime()) ||
|
||||
// WebKit browsers can mis-parse invalid dates to be ridiculously
|
||||
// huge numbers, e.g. new Date('202304') gets parsed as January 1, 202304.
|
||||
// This can cause virtually infinite loops while rendering, so for the
|
||||
// purposes of Gantt charts we'll just treat any date beyond 10,000 AD/BC as
|
||||
// invalid.
|
||||
d.getFullYear() < -10000 ||
|
||||
d.getFullYear() > 10000
|
||||
) {
|
||||
throw new Error('Invalid date:' + str);
|
||||
}
|
||||
return d;
|
||||
|
@ -432,4 +432,10 @@ describe('when using the ganttDb', function () {
|
||||
ganttDb.setTodayMarker(expected);
|
||||
expect(ganttDb.getTodayMarker()).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should reject dates with ridiculous years', function () {
|
||||
ganttDb.setDateFormat('YYYYMMDD');
|
||||
ganttDb.addTask('test1', 'id1,202304,1d');
|
||||
expect(() => ganttDb.getTasks()).toThrowError('Invalid date:202304');
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user