Skip to content

Commit

Permalink
Rejects invalid short dates
Browse files Browse the repository at this point in the history
This commit adds a validation to mark short year/month dates as invalid.
The only validation that we were doing was if Date(str) is valid, which
is but not valid as intended to be. e.g. 00-07 would be interpreted as
07/1900 by JS Date instead of 07/2000 as expected.
  • Loading branch information
mup committed Feb 3, 2025
1 parent 37aa10f commit 65f4179
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/common/misc/DateParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export function parseBirthday(text: string, referenceDateRenderer: (refdate: Dat

let day, month, year

// We must validate that NO birthdayValues is equal to 0 since we don't support only
// year and month. e.g. 07/00
if (birthdayValues.length == 2 && (birthdayValues[0] === 0 || birthdayValues[1] === 0)) {
return null
}

if (String(birthdayValues[dayPos]).length < 3 && String(birthdayValues[monthPos]).length < 3) {
if (birthdayValues[dayPos] < 32) {
day = String(birthdayValues[dayPos])
Expand Down

0 comments on commit 65f4179

Please sign in to comment.