Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow views and tables with whitespaces #15204

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/backend-core/src/sql/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function encodeTableId(tableId: string) {
}
}

export function encodeViewId(viewId: string) {
return encodeURIComponent(viewId)
}

export function breakExternalTableId(tableId: string) {
const parts = tableId.split(DOUBLE_SEPARATOR)
let datasourceId = parts.shift()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/row/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } {
if (docIds.isViewId(sourceId)) {
return {
tableId: utils.extractViewInfoFromID(sourceId).tableId,
viewId: sourceId,
viewId: sql.utils.encodeViewId(sourceId),
}
}
return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) }
Expand Down
32 changes: 31 additions & 1 deletion packages/server/src/api/routes/tests/viewV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (descriptions.length) {
let datasource: Datasource | undefined

function saveTableRequest(
...overrides: Partial<Omit<SaveTableRequest, "name">>[]
...overrides: Partial<SaveTableRequest>[]
): SaveTableRequest {
const req: SaveTableRequest = {
name: generator.guid().replaceAll("-", "").substring(0, 16),
Expand Down Expand Up @@ -1898,6 +1898,36 @@ if (descriptions.length) {
}
expect(view.queryUI).toEqual(expected)
})

it("tables and views can contain whitespaces", async () => {
const table = await config.api.table.save(
saveTableRequest({
name: `table with spaces ${generator.hash()}`,
schema: {
name: {
type: FieldType.STRING,
name: "name",
},
},
})
)

const view = await config.api.viewV2.create({
tableId: table._id!,
name: `view name with spaces`,
schema: {
name: { visible: true },
},
})

expect(await getDelegate(view)).toEqual({
...view,
schema: {
id: { ...table.schema["id"], visible: false },
name: { ...table.schema["name"], visible: true },
},
})
})
})

describe("updating table schema", () => {
Expand Down
10 changes: 2 additions & 8 deletions packages/server/src/db/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
context,
db as dbCore,
docIds,
utils,
sql,
} from "@budibase/backend-core"
import { context, db as dbCore, docIds, utils } from "@budibase/backend-core"
import {
DatabaseQueryOpts,
Datasource,
Expand Down Expand Up @@ -334,7 +328,7 @@ export function extractViewInfoFromID(viewId: string) {
const regex = new RegExp(`^(?<tableId>.+)${SEPARATOR}([^${SEPARATOR}]+)$`)
const res = regex.exec(viewId)
return {
tableId: sql.utils.encodeTableId(res!.groups!["tableId"]),
tableId: res!.groups!["tableId"],
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/server/src/tests/utilities/api/viewV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export class ViewV2API extends TestAPI {
}

get = async (viewId: string) => {
return (await this._get<ViewResponseEnriched>(`/api/v2/views/${viewId}`))
.data
return (
await this._get<ViewResponseEnriched>(
`/api/v2/views/${encodeURIComponent(viewId)}`
)
).data
}

fetch = async (expectations?: Expectations) => {
Expand Down
Loading