From 747cddfdef56d069a3cafa09fc107f43129aed6f Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 6 Nov 2024 15:51:29 +0000 Subject: [PATCH] fix: formula identifier special character bug --- packages/nc-gui/components/monaco/formula.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/components/monaco/formula.ts b/packages/nc-gui/components/monaco/formula.ts index fd50a86373..ff95ed8388 100644 --- a/packages/nc-gui/components/monaco/formula.ts +++ b/packages/nc-gui/components/monaco/formula.ts @@ -43,7 +43,17 @@ const generateLanguageDefinition = (identifiers: string[]) => { [/"/, { token: 'string.quote', bracket: '@open', next: '@dblString' }], [/'/, { token: 'string.quote', bracket: '@open', next: '@sglString' }], [ - new RegExp(`\\{(${identifiers.join('|').replace(/[{}]/g, '')})\\}`), + new RegExp( + `\\{(${identifiers + .map((identifier) => + identifier + // remove curly braces wrapping the identifier + .replace(/^\{([\s\S]+)\}$/, '$1') + // escape special characters + .replace(/[.*+?^${}()|[\]\\-]/g, '\\$&'), + ) + .join('|')})\\}`, + ), { cases: { '@identifiers': 'identifier',