diff --git a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue index 5268d64341..e52df87238 100644 --- a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue @@ -53,26 +53,31 @@ const meta = inject(MetaInj, ref()) const supportedColumns = computed( () => meta?.value?.columns?.filter((col) => !uiTypesNotSupportedInFormulas.includes(col.uidt as UITypes)) || [], ) -const { metas, getMeta } = useMetas() +const { getMeta } = useMetas() const validators = { formula_raw: [ { - validator: (_: any, formula: any) => { - return new Promise(async (resolve, reject) => { - if (!formula?.trim()) return reject(new Error('Required')) + validator: (_: any, formula: any) => { + return (async () => { + if (!formula?.trim()) throw new Error('Required') try { - await validateFormulaAndExtractTreeWithType({ column: column.value, formula, columns: supportedColumns.value, clientOrSqlUi: sqlUi.value, getMeta }) + await validateFormulaAndExtractTreeWithType({ + column: column.value, + formula, + columns: supportedColumns.value, + clientOrSqlUi: sqlUi.value, + getMeta, + }) } catch (e: any) { if (e instanceof FormulaError && e.extra?.key) { - return reject(new Error(t(e.extra.key, e.extra))) + throw new Error(t(e.extra.key, e.extra)) } - return reject(new Error(e.message)) + throw new Error(e.message) } - resolve() - }) + })() }, }, ], diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index 571355083e..401712cd93 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -241,7 +241,7 @@ export function jsepTreeToFormula(node, isCallExpId = false) { function escapeLiteral(v: string) { return ( v - // replace \ to \\ + // replace \ to \\, escape only unescaped \ .replace(/([^\\]|^)\\(?!\\)/g, `$1\\\\`) // replace " to \" .replace(/([^\\]|^)"/g, `$1\\"`) diff --git a/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts b/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts index 2df5d90b5a..643f5c4d0a 100644 --- a/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts +++ b/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts @@ -60,7 +60,7 @@ export default class XcMigrationSourcev2 { 'nc_035_add_username_to_users', 'nc_036_base_deleted', 'nc_037_rename_project_and_base', - 'nc_038_formula_parsed_tree_column' + 'nc_038_formula_parsed_tree_column', ]); }