From 249b6c8cf101343b6bf3c4958ad05ffc4dbdd99a Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Mon, 28 Oct 2024 14:49:32 +0100 Subject: [PATCH 1/2] handle nbsp --- .../__tests__/parseEditorContent.test.ts | 29 +++++++++++++++++++ .../utils/parseEditorContent.ts | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts b/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts index 1302ebb04a0f..537530d23a1c 100644 --- a/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts +++ b/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts @@ -267,4 +267,33 @@ describe('parseEditorContent', () => { expect(parseEditorContent(input)).toBe('First line\nSecond line'); }); + + it('should handle spaces between variables correctly', () => { + const input: JSONContent = { + type: 'doc', + content: [ + { + type: 'paragraph', + content: [ + { + type: 'variableTag', + attrs: { variable: '{{user.firstName}}' }, + }, + { + type: 'text', + text: '\u00A0', // NBSP character + }, + { + type: 'variableTag', + attrs: { variable: '{{user.lastName}}' }, + }, + ], + }, + ], + }; + + expect(parseEditorContent(input)).toBe( + '{{user.firstName}} {{user.lastName}}', + ); + }); }); diff --git a/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts b/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts index ebad7f0e9734..1609aa545c87 100644 --- a/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts +++ b/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts @@ -11,7 +11,8 @@ export const parseEditorContent = (json: JSONContent): string => { } if (node.type === 'text') { - return node.text || ''; + // Replace   with regular space + return (node.text || '').replace(/\u00A0/g, ' '); } if (node.type === 'hardBreak') { From 68200be4461e9a047991f1a6fcbda9d3d0b14349 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Mon, 28 Oct 2024 15:31:38 +0100 Subject: [PATCH 2/2] Update syntax --- .../workflow/search-variables/utils/parseEditorContent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts b/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts index 1609aa545c87..c27e655d0021 100644 --- a/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts +++ b/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts @@ -12,7 +12,7 @@ export const parseEditorContent = (json: JSONContent): string => { if (node.type === 'text') { // Replace   with regular space - return (node.text || '').replace(/\u00A0/g, ' '); + return node?.text?.replace(/\u00A0/g, ' ') ?? ''; } if (node.type === 'hardBreak') {