Skip to content

fix(isDate): return false when the format delimiter is not allowed - #2953

Open
kevin9327 wants to merge 1 commit into
validatorjs:masterfrom
kevin9327:fix/isdate-format-delimiter
Open

kevin9327 wants to merge 1 commit into
validatorjs:masterfrom
kevin9327:fix/isdate-format-delimiter

Conversation

@kevin9327

Copy link
Copy Markdown

isDate throws a TypeError instead of returning false when the delimiter used in format is not in delimiters:

isDate('29.02.2020', 'DD.MM.YYYY');           // TypeError: Cannot read properties of undefined (reading 'startsWith')
isDate('2020.02.29', { format: 'YYYY.MM.DD' }); // TypeError: Cannot read properties of undefined (reading 'length')
isDate('2020-02-29', { format: 'YYYY-MM-DD', delimiters: ['/'] }); // TypeError

isValidFormat accepts . as a format delimiter, but the default delimiters are ['/', '-']. So formatDelimiter is undefined, split(undefined) keeps the whole string as one part, and when the input has the same length as the format, dateObj.y / dateObj.m are never set. Inputs of other lengths already return false.

Since the format's delimiter isn't an allowed one, no input can match. The fix returns false in that case, which is what other mismatched inputs already get. Passing delimiters: ['.'] keeps working as before.

Related to #1709 (where . formats were enabled).

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

AI-assistance note: I found this bug and drafted the fix with help from an AI coding assistant, then checked the change and ran the test suite locally.

@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (bc0bcf7).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2953   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2600    +1     
  Branches       658       659    +1     
=========================================
+ Hits          2599      2600    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant