flatpickr / flatpickr

lightweight, powerful javascript datetimepicker with no dependencies

Home Page:https://flatpickr.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parseDate does not throw error for invalid dates when allowInput

tay1orjones opened this issue · comments

Repro: https://jsfiddle.net/b9jtc1m6/1/

Steps to reproduce

  1. Enter date of 77/77/7777 and hit enter
  2. Observe the date is parsed to 07/16/7783

I'm not sure if this is an error in createDateParser or createDateFormatter, but this date should result in an "Invalid date provided" because the month m is not 01-12, and the day d is not 01 to 31 as specified in the docs.

Your Environment

  • flatpickr version used: 4.6.13
  • Browser name and version: Chrome 121.0.6167.184 (Official Build) (arm64)
  • OS and version: MacOS 13.6 (22G120)

I figured out the issue. The formatting code doesn't guard against values greater than what's specified in the docs.

d: (dateObj: Date, day: string) => {
dateObj.setDate(parseFloat(day));
},

m: (dateObj: Date, month: string) => {
dateObj.setMonth(parseFloat(month) - 1);
},

This is due to the behavior of the native date methods:

If a parameter you specify is outside of the expected range, other parameters and the date information in the Date object are updated accordingly. For example, if you specify 15 for monthValue, the year is incremented by 1, and 3 is used for month.