mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-10-31 02:44:17 +01:00 
			
		
		
		
	Merge pull request #4367 from toolness/bug/4353_reject_ridiculous_dates
Reject ridiculous years in Gantt charts.
This commit is contained in:
		| @@ -287,7 +287,17 @@ const getStartDate = function (prevTime, dateFormat, str) { | |||||||
|     log.debug('Invalid date:' + str); |     log.debug('Invalid date:' + str); | ||||||
|     log.debug('With date format:' + dateFormat.trim()); |     log.debug('With date format:' + dateFormat.trim()); | ||||||
|     const d = new Date(str); |     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); |       throw new Error('Invalid date:' + str); | ||||||
|     } |     } | ||||||
|     return d; |     return d; | ||||||
|   | |||||||
| @@ -432,4 +432,10 @@ describe('when using the ganttDb', function () { | |||||||
|     ganttDb.setTodayMarker(expected); |     ganttDb.setTodayMarker(expected); | ||||||
|     expect(ganttDb.getTodayMarker()).toEqual(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'); | ||||||
|  |   }); | ||||||
| }); | }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Sidharth Vinod
					Sidharth Vinod