fix(cli-date): reject month/day overflow in parseLocalDate#111
fix(cli-date): reject month/day overflow in parseLocalDate#111lfl1337 wants to merge 1 commit intogetagentseal:mainfrom
Conversation
parseLocalDate validated the YYYY-MM-DD shape via regex but relied on the Date constructor to normalize values. That meant inputs like 2026-13-45 or 2026-02-30 silently rolled forward into a different valid date, and --from/--to then produced a misleading "must not be after" error instead of rejecting the input. Check the round-tripped fields against the parsed numbers and throw a clear "month or day out of range" error when they diverge.
firstlook
Details
|
|
Hi, parseLocalDate now rejects inputs where Date round-tripping changes the parsed year, but JavaScript interprets years 0–99 as 1900–1999. Dates like "0099-01-01" will incorrectly throw "month or day out of range" despite matching the YYYY-MM-DD format contract. Severity: action required | Category: correctness How to fix: Handle years 0–99 explicitly Agent prompt to fix - you can give this to your LLM of choice:
Found by Qodo code review. FYI, Qodo is free for open-source. |
Summary
Follow-up to #80, which introduced
parseLocalDate. The regex-onlyvalidation there accepts structurally valid but semantically invalid
dates like
2026-13-45or2026-02-30. TheDateconstructorsilently rolls them forward into a different valid date, so
--from/--tothen produce a misleading"must not be after"error insteadof rejecting the input.
Fix
After constructing the
Date, compare the round-trippedyear / month / dayback to the parsed numbers. If they diverge,throw a clear
"month or day out of range"error.Before
After
Tests
Two new cases in
tests/date-range-filter.test.tscover month and dayoverflow. Full file 10/10 green.