From f857c36e09813c3224be4afaa5d6809f0612ccbf Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 12 Dec 2024 16:50:21 +0000 Subject: [PATCH] PR comments. --- packages/backend-core/src/sql/utils.ts | 10 +++------- packages/server/src/api/controllers/row/utils/utils.ts | 10 ++++------ packages/server/src/db/utils.ts | 10 ++++++++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/backend-core/src/sql/utils.ts b/packages/backend-core/src/sql/utils.ts index f1e0c4c5ce..14127a189f 100644 --- a/packages/backend-core/src/sql/utils.ts +++ b/packages/backend-core/src/sql/utils.ts @@ -59,15 +59,11 @@ export function isExternalTable(table: Table) { } export function buildExternalTableId(datasourceId: string, tableName: string) { - // encode spaces - if (tableName.includes(" ")) { - tableName = encodeURIComponent(tableName) - } - return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}` + return `${datasourceId}${DOUBLE_SEPARATOR}${encodeURIComponent(tableName)}` } -export function checkTableId(tableId: string) { - if (isExternalTableID(tableId) && tableId.includes(" ")) { +export function encodeTableId(tableId: string) { + if (isExternalTableID(tableId)) { return encodeURIComponent(tableId) } else { return tableId diff --git a/packages/server/src/api/controllers/row/utils/utils.ts b/packages/server/src/api/controllers/row/utils/utils.ts index b729d7470d..baa811fe90 100644 --- a/packages/server/src/api/controllers/row/utils/utils.ts +++ b/packages/server/src/api/controllers/row/utils/utils.ts @@ -65,21 +65,19 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } { const { sourceId } = ctx.params if (docIds.isViewId(sourceId)) { return { - tableId: sql.utils.checkTableId( - utils.extractViewInfoFromID(sourceId).tableId - ), + tableId: utils.extractViewInfoFromID(sourceId).tableId, viewId: sourceId, } } - return { tableId: sql.utils.checkTableId(ctx.params.sourceId) } + return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) } } // now check for old way of specifying table ID if (ctx.params?.tableId) { - return { tableId: sql.utils.checkTableId(ctx.params.tableId) } + return { tableId: sql.utils.encodeTableId(ctx.params.tableId) } } // check body for a table ID if (ctx.request.body?.tableId) { - return { tableId: sql.utils.checkTableId(ctx.request.body.tableId) } + return { tableId: sql.utils.encodeTableId(ctx.request.body.tableId) } } throw new Error("Unable to find table ID in request") } diff --git a/packages/server/src/db/utils.ts b/packages/server/src/db/utils.ts index 6c1065e847..70c69b3c60 100644 --- a/packages/server/src/db/utils.ts +++ b/packages/server/src/db/utils.ts @@ -1,4 +1,10 @@ -import { context, db as dbCore, docIds, utils } from "@budibase/backend-core" +import { + context, + db as dbCore, + docIds, + utils, + sql, +} from "@budibase/backend-core" import { DatabaseQueryOpts, Datasource, @@ -328,7 +334,7 @@ export function extractViewInfoFromID(viewId: string) { const regex = new RegExp(`^(?.+)${SEPARATOR}([^${SEPARATOR}]+)$`) const res = regex.exec(viewId) return { - tableId: res!.groups!["tableId"], + tableId: sql.utils.encodeTableId(res!.groups!["tableId"]), } }