Browse Source

Merge pull request #5316 from nocodb/fix/formula

fix(sdk): escapeLiteral
pull/5322/head
Raju Udava 2 years ago committed by GitHub
parent
commit
29a598986d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

14
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -179,7 +179,7 @@ export function jsepTreeToFormula(node) {
if (node.type === 'Literal') { if (node.type === 'Literal') {
if (typeof node.value === 'string') { if (typeof node.value === 'string') {
return String.raw`"${escapeDoubleQuotes(node.value)}"`; return String.raw`"${escapeLiteral(node.value)}"`;
} }
return '' + node.value; return '' + node.value;
} }
@ -214,6 +214,14 @@ export function jsepTreeToFormula(node) {
return ''; return '';
} }
function escapeDoubleQuotes(v: string) { function escapeLiteral(v: string) {
return v.replace(/"/g, '\\"'); return (
v
// replace \ to \\
.replace(/\\/g, `\\\\`)
// replace " to \"
.replace(/"/g, `\\"`)
// replace ' to \'
.replace(/'/g, `\\'`)
);
} }

Loading…
Cancel
Save