forked from GitHubMirrors/silverbullet-icalendar
fix(icalendar): Handle non-string rrule property gracefully
This commit is contained in:
@@ -154,6 +154,11 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] {
|
|||||||
const rruleStr = icsEvent.rrule || (icsEvent as any).recurrenceRule;
|
const rruleStr = icsEvent.rrule || (icsEvent as any).recurrenceRule;
|
||||||
if (!rruleStr) return [icsEvent];
|
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 {
|
try {
|
||||||
const set = new RRuleSet();
|
const set = new RRuleSet();
|
||||||
const cleanRule = rruleStr.replace(/^RRULE:/i, "");
|
const cleanRule = rruleStr.replace(/^RRULE:/i, "");
|
||||||
|
|||||||
@@ -132,23 +132,25 @@ Deno.test("expandRecurrences - non-string rrule (Reproduction)", () => {
|
|||||||
rrule: 12345 // Simulating the malformed data
|
rrule: 12345 // Simulating the malformed data
|
||||||
};
|
};
|
||||||
|
|
||||||
// Spy on console.error
|
// Spy on console.warn
|
||||||
let errorLogged = false;
|
let warningLogged = false;
|
||||||
const originalConsoleError = console.error;
|
const originalConsoleWarn = console.warn;
|
||||||
console.error = (...args) => {
|
console.warn = (...args) => {
|
||||||
if (args[0].includes("Error expanding recurrence for Bug Reproduction Event") &&
|
if (args[0].includes("Invalid rrule type (number) for event \"Bug Reproduction Event\"")) {
|
||||||
args[1] instanceof TypeError) {
|
warningLogged = true;
|
||||||
errorLogged = true;
|
|
||||||
}
|
}
|
||||||
// originalConsoleError(...args); // Keep silent for test
|
// originalConsoleWarn(...args); // Keep silent for test
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
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 {
|
} 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");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user