From 5952490507176c21110e26eea83abbe556ae0942 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Sat, 28 Mar 2026 13:02:23 +0800 Subject: [PATCH] Fix Date#setDay validation for all 30-day months IoDate_setDay only applied the 30-day guard to November (11), so April, June, and September accepted day 31 against the calendar. Apply the same bounds check to months 4, 6, 9, and 11. Add DateTest regression coverage and isLaunchScript runner for direct io DateTest.io runs. --- libs/iovm/source/IoDate.c | 2 +- libs/iovm/tests/correctness/DateTest.io | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/iovm/source/IoDate.c b/libs/iovm/source/IoDate.c index cc7062d02..8ca715512 100644 --- a/libs/iovm/source/IoDate.c +++ b/libs/iovm/source/IoDate.c @@ -275,7 +275,7 @@ IO_METHOD(IoDate, setDay) { } else { IOASSERT(v >= 1 && v <= 28, "day must be within range 1-28"); } - } else if (month == 11) { + } else if (month == 4 || month == 6 || month == 9 || month == 11) { IOASSERT(v >= 1 && v <= 30, "day must be within range 1-30"); } else if (month == 12) { IOASSERT(v >= 1 && v <= 31, "day must be within range 1-31"); diff --git a/libs/iovm/tests/correctness/DateTest.io b/libs/iovm/tests/correctness/DateTest.io index ddef2048f..6897efe36 100644 --- a/libs/iovm/tests/correctness/DateTest.io +++ b/libs/iovm/tests/correctness/DateTest.io @@ -79,5 +79,16 @@ DateTest := UnitTest clone do( //testString("%x") #%x is locale dependent testString("%y") ) + + // Regression: setDay must reject day 31 in 30-day months (Apr/Jun/Sep/Nov). + // Previously only November was checked; April/June/September could accept 31 incorrectly. + testSetDayThirtyDayMonths := method( + assertRaisesException(Date clone setMonth(4) setDay(31)) + assertRaisesException(Date clone setMonth(6) setDay(31)) + assertRaisesException(Date clone setMonth(9) setDay(31)) + assertRaisesException(Date clone setMonth(11) setDay(31)) + ) ) +if(isLaunchScript, DateTest run, DateTest) +