bendavis78 / paper-date-picker

Material design date picker component for polymer
http://bendavis78.github.io/paper-date-picker/
MIT License
226 stars 132 forks source link

_dateChanged function in paper-calendar doesn't validate maxDate and minDate #199

Open xd1gital opened 6 years ago

xd1gital commented 6 years ago

this.maxDate and this.minDate need to be validated (null checking) before calling .getFullYear()

 _dateChanged: function(date, oldValue) {
        if (!this._isValidDate(date)) {
          console.warn('Invalid date: ' + date);
          this.date = date = oldValue;
        }
        if (!this._withinValidRange(date)) {
          console.warn('Date outside of valid range: ' + date);
          if(date.getFullYear() == **this.maxDate**.getFullYear()) {
            this.date = this.maxDate;
          } else if(date.getFullYear() == **this.minDate**.getFullYear()){
            this.date = this.minDate;
          } else {
            this.date = date = oldValue;
          }
        }
...
admwx7 commented 6 years ago

The root of the issue is not validating that a property defined as a Date is actually a date and not currently set to null (or any non-date value for that matter), this type of issue can be found in these locations: https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-calendar.html#L245 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-calendar.html#L323 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-calendar.html#L552 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-calendar.html#L660 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-calendar.html#L689 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-calendar.html#L704 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-year-list.html#L147 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-year-list.html#L169 https://github.com/bendavis78/paper-date-picker/blob/2.0.0-rc2/paper-date-picker.html#L283