Browse Source

fix(sdk): escapeLiteral

pull/5316/head
Wing-Kam Wong 2 years ago
parent
commit
d8e662c1f1
  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