From d8e662c1f19fa1a87f739f4172438a68ece8bfce Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Mar 2023 12:44:40 +0800 Subject: [PATCH] fix(sdk): escapeLiteral --- packages/nocodb-sdk/src/lib/formulaHelpers.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index 4d71420952..08b519e9da 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -179,7 +179,7 @@ export function jsepTreeToFormula(node) { if (node.type === 'Literal') { if (typeof node.value === 'string') { - return String.raw`"${escapeDoubleQuotes(node.value)}"`; + return String.raw`"${escapeLiteral(node.value)}"`; } return '' + node.value; } @@ -214,6 +214,14 @@ export function jsepTreeToFormula(node) { return ''; } -function escapeDoubleQuotes(v: string) { - return v.replace(/"/g, '\\"'); +function escapeLiteral(v: string) { + return ( + v + // replace \ to \\ + .replace(/\\/g, '\\\\') + // replace " to \" + .replace(/"/g, '\\"') + // replace ' to \' + .replace(/'/g, '\\"') + ); }