From f8640533be3ac4f6699ccd109ebbb5487142ac83 Mon Sep 17 00:00:00 2001 From: sstent Date: Fri, 20 Feb 2026 08:42:06 -0800 Subject: [PATCH] fix(icalendar): Handle non-string rrule property gracefully --- icalendar.ts | 5 +++++ icalendar_test.ts | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/icalendar.ts b/icalendar.ts index 2a575b6..6160c70 100644 --- a/icalendar.ts +++ b/icalendar.ts @@ -154,6 +154,11 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] { const rruleStr = icsEvent.rrule || (icsEvent as any).recurrenceRule; if (!rruleStr) return [icsEvent]; + if (typeof rruleStr !== "string") { + console.warn(`[iCalendar] Invalid rrule type (${typeof rruleStr}) for event "${icsEvent.summary || "Untitled"}". Treating as non-recurring.`); + return [icsEvent]; + } + try { const set = new RRuleSet(); const cleanRule = rruleStr.replace(/^RRULE:/i, ""); diff --git a/icalendar_test.ts b/icalendar_test.ts index 8842f14..7572c33 100644 --- a/icalendar_test.ts +++ b/icalendar_test.ts @@ -132,23 +132,25 @@ Deno.test("expandRecurrences - non-string rrule (Reproduction)", () => { rrule: 12345 // Simulating the malformed data }; - // Spy on console.error - let errorLogged = false; - const originalConsoleError = console.error; - console.error = (...args) => { - if (args[0].includes("Error expanding recurrence for Bug Reproduction Event") && - args[1] instanceof TypeError) { - errorLogged = true; + // Spy on console.warn + let warningLogged = false; + const originalConsoleWarn = console.warn; + console.warn = (...args) => { + if (args[0].includes("Invalid rrule type (number) for event \"Bug Reproduction Event\"")) { + warningLogged = true; } - // originalConsoleError(...args); // Keep silent for test + // originalConsoleWarn(...args); // Keep silent for test }; try { - expandRecurrences(icsEvent, 30); + const result = expandRecurrences(icsEvent, 30); + // Should return the original event as fallback + assertEquals(result.length, 1); + assertEquals(result[0], icsEvent); } finally { - console.error = originalConsoleError; + console.warn = originalConsoleWarn; } - assert(errorLogged, "Should have logged an error for non-string rrule"); + assert(warningLogged, "Should have logged a warning for non-string rrule"); });