Skip to content

Commit 095e392

Browse files
authored
EvaluationOptions: Fix off-by-one issue of MaxUnmatchedIncrementsLimit (#775)
EvaluationOptions: Fix off-by-one issue with `MaxUnmatchedIncrementsLimit`
1 parent 92227d2 commit 095e392

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

Ical.Net.Tests/RecurrenceTests.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,22 +3916,35 @@ public void TestDtStartTimezone(string? tzId)
39163916
Assert.That(expectedStartTimes.SequenceEqual(occurrencesStartTimes), Is.True);
39173917
}
39183918

3919-
[Test]
3920-
[TestCase(null, false)]
3921-
[TestCase(0, true)]
3922-
[TestCase(1000, true)]
3923-
[TestCase(1440, false)]
3924-
public void TestMaxIncrementCount(int? limit, bool expectException)
3925-
{
3926-
var ical = """
3919+
// Between 00:59 and 00:00 there's a gap of 1380 minutes, which is 690 increments.
3920+
private const string TestMaxIncrementCountWithGaps = """
39273921
BEGIN:VCALENDAR
39283922
BEGIN:VEVENT
39293923
DTSTART:20250305T000000
3930-
RRULE:FREQ=MINUTELY;BYHOUR=0;COUNT=100
3924+
RRULE:FREQ=MINUTELY;INTERVAL=2;BYHOUR=0;COUNT=100
39313925
END:VEVENT
39323926
END:VCALENDAR
39333927
""";
39343928

3929+
private const string TestMaxIncrementCountWithoutGaps = """
3930+
BEGIN:VCALENDAR
3931+
BEGIN:VEVENT
3932+
DTSTART:20250305T000000
3933+
RRULE:FREQ=DAILY;INTERVAL=10;COUNT=100
3934+
END:VEVENT
3935+
END:VCALENDAR
3936+
""";
3937+
3938+
[Test]
3939+
[TestCase(null, TestMaxIncrementCountWithGaps, false)]
3940+
[TestCase(0, TestMaxIncrementCountWithGaps, true)]
3941+
[TestCase(1, TestMaxIncrementCountWithGaps, true)]
3942+
[TestCase(689, TestMaxIncrementCountWithGaps, true)]
3943+
[TestCase(690, TestMaxIncrementCountWithGaps, false)]
3944+
[TestCase(0, TestMaxIncrementCountWithoutGaps, false)]
3945+
[TestCase(1, TestMaxIncrementCountWithoutGaps, false)]
3946+
public void TestMaxIncrementCount(int? limit, string ical, bool expectException)
3947+
{
39353948
var cal = Calendar.Load(ical);
39363949

39373950
var options = new EvaluationOptions

Ical.Net/Evaluation/RecurrencePatternEvaluator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ private IEnumerable<CalDateTime> EnumerateDates(CalDateTime originalDate, CalDat
192192
dateCount++;
193193
}
194194

195-
noCandidateIncrementCount++;
196195
if (noCandidateIncrementCount > options?.MaxUnmatchedIncrementsLimit)
197196
throw new EvaluationLimitExceededException();
198197

198+
noCandidateIncrementCount++;
199+
199200
IncrementDate(ref intervalRefTime, pattern, pattern.Interval);
200201
}
201202
}

0 commit comments

Comments
 (0)