Skip to content

The open alternative to Salesforce, designed for AI.

escaping special chars for events (#12872)

Guillimfa09adee8ee9
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 278ab7b06b5..705de5c0bb5 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 mockGoogleEventWithImproperUcalid: calendarV3.Schema$Event = {
- ...mockGoogleEvent,
- iCalUID: '\[email protected]',
- };
+ const testCases: EachTestingContext<{ input: string; expected: string }>[] = [
+ {
+ title: 'should sanitize a UCALID with \u0000',
+ context: {
+ input: '\[email protected]',
+ expected: '[email protected]',
+ },
+ },
+ {
+ 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��',
+ },
+ },
+ ];
- const mockGoogleEventWithImproperUcalid2: calendarV3.Schema$Event = {
+ it.each(testCases)('$title', ({ context }) => {
+ const mockGoogleEventWithImproperUcalid: calendarV3.Schema$Event = {
...mockGoogleEvent,
- iCalUID: '>\u0000\u0015-;_�^�W&�p\u001f�',
+ iCalUID: context.input,
};
const result = formatGoogleCalendarEvents([
mockGoogleEventWithImproperUcalid,
- mockGoogleEventWithImproperUcalid2,
]);
- expect(result[0].iCalUID).toBe('[email protected]');
- 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 5e6ee2756e7..809da8882e4 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 = <T extends Record<string, any>>(
};
const sanitizeString = (value: string): string => {
- return value.replace('\u0000', '');
+ return value.replace('\u0000', '').replace('\x00', '').replace('\x7f', '');
};