diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/utils/__tests__/format-google-calendar-event.util.spec.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/utils/__tests__/format-google-calendar-event.util.spec.ts index 278ab7b06..705de5c0b 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/utils/__tests__/format-google-calendar-event.util.spec.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/utils/__tests__/format-google-calendar-event.util.spec.ts @@ -1,4 +1,5 @@ import { calendar_v3 as calendarV3 } from 'googleapis'; +import { EachTestingContext } from 'twenty-shared/testing'; import { formatGoogleCalendarEvents } from 'src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/utils/format-google-calendar-event.util'; import { CalendarEventParticipantResponseStatus } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; @@ -77,23 +78,48 @@ describe('formatGoogleCalendarEvents', () => { ); }); - it('should sanitize a UCALID with improper exit char 0x00', () => { + const testCases: EachTestingContext<{ input: string; expected: string }>[] = [ + { + title: 'should sanitize a UCALID with \u0000', + context: { + input: '\u0000eventStrange@google.com', + expected: 'eventStrange@google.com', + }, + }, + { + title: 'should sanitize a UCALID with \u0000', + context: { + input: '>\u0000\u0015-;_�^�W&�p\u001f�', + expected: '>\u0015-;_�^�W&�p\u001f�', + }, + }, + { + title: 'should sanitize a UCALID with \x00', + context: { + input: '�\u0002��y�_΢�\u0013��\x00', + expected: '�\u0002��y�_΢�\u0013��', + }, + }, + + { + title: 'should sanitize a UCALID with del', + context: { + input: 'del�\u0002��y�_΢�\u0013��', + expected: 'del�\u0002��y�_΢�\u0013��', + }, + }, + ]; + + it.each(testCases)('$title', ({ context }) => { const mockGoogleEventWithImproperUcalid: calendarV3.Schema$Event = { ...mockGoogleEvent, - iCalUID: '\u0000eventStrange@google.com', - }; - - const mockGoogleEventWithImproperUcalid2: calendarV3.Schema$Event = { - ...mockGoogleEvent, - iCalUID: '>\u0000\u0015-;_�^�W&�p\u001f�', + iCalUID: context.input, }; const result = formatGoogleCalendarEvents([ mockGoogleEventWithImproperUcalid, - mockGoogleEventWithImproperUcalid2, ]); - expect(result[0].iCalUID).toBe('eventStrange@google.com'); - expect(result[1].iCalUID).toBe('>\u0015-;_�^�W&�p\u001f�'); + expect(result[0].iCalUID).toBe(context.expected); }); }); diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/utils/sanitizeCalendarEvent.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/utils/sanitizeCalendarEvent.ts index 5e6ee2756..809da8882 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/utils/sanitizeCalendarEvent.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/utils/sanitizeCalendarEvent.ts @@ -23,5 +23,5 @@ export const sanitizeCalendarEvent = >( }; const sanitizeString = (value: string): string => { - return value.replace('\u0000', ''); + return value.replace('\u0000', '').replace('\x00', '').replace('\x7f', ''); };