diff --git a/packages/lib/CalendarService.ts b/packages/lib/CalendarService.ts index 779e70f732..392610a836 100644 --- a/packages/lib/CalendarService.ts +++ b/packages/lib/CalendarService.ts @@ -17,6 +17,7 @@ import { import { v4 as uuidv4 } from "uuid"; import dayjs from "@calcom/dayjs"; +import sanitizeCalendarObject from "@calcom/lib/sanitizeCalendarObject"; import type { Calendar, CalendarEvent, @@ -177,7 +178,6 @@ export default abstract class BaseCalendarService implements Calendar { } const eventsToUpdate = events.filter((e) => e.uid === uid); - return Promise.all( eventsToUpdate.map((e) => { return updateCalendarObject({ @@ -251,9 +251,13 @@ export default abstract class BaseCalendarService implements Calendar { objects.forEach((object) => { if (object.data == null) return; - const jcalData = ICAL.parse(object.data); + const jcalData = ICAL.parse(sanitizeCalendarObject(object)); const vcalendar = new ICAL.Component(jcalData); const vevent = vcalendar.getFirstSubcomponent("vevent"); + + // if event status is free or transparent, return + if (vevent?.getFirstPropertyValue("transp") === "TRANSPARENT") return; + const event = new ICAL.Event(vevent); const vtimezone = vcalendar.getFirstSubcomponent("vtimezone"); @@ -266,7 +270,6 @@ export default abstract class BaseCalendarService implements Calendar { const start = dayjs(dateFrom); const end = dayjs(dateTo); - const iterator = event.iterator(); let current; let currentEvent; @@ -379,7 +382,7 @@ export default abstract class BaseCalendarService implements Calendar { const events = objects .filter((e) => !!e.data) .map((object) => { - const jcalData = ICAL.parse(object.data); + const jcalData = ICAL.parse(sanitizeCalendarObject(object)); const vcalendar = new ICAL.Component(jcalData); diff --git a/packages/lib/sanitizeCalendarObject.ts b/packages/lib/sanitizeCalendarObject.ts new file mode 100644 index 0000000000..19c52c8dc2 --- /dev/null +++ b/packages/lib/sanitizeCalendarObject.ts @@ -0,0 +1,12 @@ +import { DAVObject } from "tsdav"; + +export const sanitizeCalendarObject = (obj: DAVObject) => { + return obj.data + .replaceAll("\r\n", "\r") + .replaceAll("\r", "\r\n") + .replaceAll(/(: \r\n|:\r\n|\r\n:|\r\n :)/gm, ":") + .replaceAll(/(; \r\n|;\r\n|\r\n;|\r\n ;)/gm, ";") + .replaceAll(/(= \r\n|=\r\n|\r\n=|\r\n =)/gm, "="); +}; + +export default sanitizeCalendarObject;