diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index e10e491dea..4d71420952 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -179,9 +179,8 @@ export function jsepTreeToFormula(node) { if (node.type === 'Literal') { if (typeof node.value === 'string') { - return '"' + node.value + '"'; + return String.raw`"${escapeDoubleQuotes(node.value)}"`; } - return '' + node.value; } @@ -214,3 +213,7 @@ export function jsepTreeToFormula(node) { return ''; } + +function escapeDoubleQuotes(v: string) { + return v.replace(/"/g, '\\"'); +} diff --git a/packages/nocodb/src/lib/utils/common/helpers/jsepTreeToFormula.ts b/packages/nocodb/src/lib/utils/common/helpers/jsepTreeToFormula.ts deleted file mode 100644 index 5532d229f0..0000000000 --- a/packages/nocodb/src/lib/utils/common/helpers/jsepTreeToFormula.ts +++ /dev/null @@ -1,67 +0,0 @@ -export default function jsepTreeToFormula(node) { - if (node.type === 'BinaryExpression' || node.type === 'LogicalExpression') { - return ( - '(' + - jsepTreeToFormula(node.left) + - ' ' + - node.operator + - ' ' + - jsepTreeToFormula(node.right) + - ')' - ); - } - - if (node.type === 'UnaryExpression') { - return node.operator + jsepTreeToFormula(node.argument); - } - - if (node.type === 'MemberExpression') { - return ( - jsepTreeToFormula(node.object) + - '[' + - jsepTreeToFormula(node.property) + - ']' - ); - } - - if (node.type === 'Identifier') { - return node.name; - } - - if (node.type === 'Literal') { - if (typeof node.value === 'string') { - return '"' + node.value + '"'; - } - - return '' + node.value; - } - - if (node.type === 'CallExpression') { - return ( - jsepTreeToFormula(node.callee) + - '(' + - node.arguments.map(jsepTreeToFormula).join(', ') + - ')' - ); - } - - if (node.type === 'ArrayExpression') { - return '[' + node.elements.map(jsepTreeToFormula).join(', ') + ']'; - } - - if (node.type === 'Compound') { - return node.body.map((e) => jsepTreeToFormula(e)).join(' '); - } - - if (node.type === 'ConditionalExpression') { - return ( - jsepTreeToFormula(node.test) + - ' ? ' + - jsepTreeToFormula(node.consequent) + - ' : ' + - jsepTreeToFormula(node.alternate) - ); - } - - return ''; -} diff --git a/packages/nocodb/src/lib/utils/common/helpers/updateColumnNameInFormula.ts b/packages/nocodb/src/lib/utils/common/helpers/updateColumnNameInFormula.ts index d8d5834529..7ddd4c2a46 100644 --- a/packages/nocodb/src/lib/utils/common/helpers/updateColumnNameInFormula.ts +++ b/packages/nocodb/src/lib/utils/common/helpers/updateColumnNameInFormula.ts @@ -1,4 +1,4 @@ -import jsepTreeToFormula from './jsepTreeToFormula'; +import { jsepTreeToFormula } from 'nocodb-sdk'; export default function (args: { virtualColumns;