smalot / bootstrap-datetimepicker

Both Date and Time picker widget based on twitter bootstrap (supports Bootstrap v2 and v3)
http://www.malot.fr/bootstrap-datetimepicker/
Apache License 2.0
3.49k stars 1.65k forks source link

Function timeZoneAbbreviation can crash the page #652

Open turkboris opened 7 years ago

turkboris commented 7 years ago

There is an error in https://github.com/smalot/bootstrap-datetimepicker/blob/master/js/bootstrap-datetimepicker.js

Example: date = "Tue Apr 18 17:15:13 UTC+0200 2017"

In function timeZoneAbbreviation... When date.split('(')[1] is not null, that doesn't mean it is not undefined. When it is undefined, the script tries to executes ref.slice(0, -1) and the page crashes. This happens in older IE browsers and also Firefox.

Wrong: formattedStr = ((ref = date.split('(')[1]) !== null ? ref.slice(0, -1) : 0) || date.split(' ');

Correct: formattedStr = (((ref = date.split('(')[1]) !== null && (ref = date.split('(')[1]) !== undefined) ? ref.slice(0, -1) : 0) || date.split(' ');