From 240a8fd323c7eb6056d2f5d2a7b93d61d3de9664 Mon Sep 17 00:00:00 2001 From: Pranav C Balan Date: Wed, 16 Jun 2021 20:50:37 +0530 Subject: [PATCH] fix: Handle whitespace in api path Signed-off-by: Pranav C Balan --- packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts | 4 ++-- packages/nocodb/src/lib/noco/rest/RestBaseCtrl.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts index a59a0671ce..db6fddec35 100644 --- a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts +++ b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts @@ -198,7 +198,7 @@ export class RestApiBuilder extends BaseApiBuilder { if (!rootPath) { continue; } - this.router.use(rootPath, router); + this.router.use(encodeURI(rootPath), router); this.apiCount += routes.length; this.controllers[meta.title] = new RestCtrl(this.app, this.models, meta.title, routes, rootPath, this.acls, middlewareBody); @@ -439,7 +439,7 @@ export class RestApiBuilder extends BaseApiBuilder { /* create table controllers and map the routes */ this.controllers[table.tn] = new RestCtrl(this.app, this.models, table.tn, routes, rootPath, this.acls, null); this.controllers[table.tn].mapRoutes(router, this.customRoutes); - this.router.use(rootPath, router); + this.router.use(encodeURI(rootPath), router); /* handle relational routes */ relationRoutes.push(async () => { diff --git a/packages/nocodb/src/lib/noco/rest/RestBaseCtrl.ts b/packages/nocodb/src/lib/noco/rest/RestBaseCtrl.ts index 34d3483d9e..b98e32763f 100644 --- a/packages/nocodb/src/lib/noco/rest/RestBaseCtrl.ts +++ b/packages/nocodb/src/lib/noco/rest/RestBaseCtrl.ts @@ -32,7 +32,7 @@ export abstract class RestBaseCtrl { handlers.push(this.postMiddleware); - router[addRoute.method](addRoute.path.slice(this.rootPath.length), ...handlers); + router[addRoute.method](encodeURI(addRoute.path.slice(this.rootPath.length)), ...handlers); }) @@ -55,7 +55,7 @@ export abstract class RestBaseCtrl { handlers.push(this.postMiddleware); - router[route.type](route.path.slice(this.rootPath.length), ...handlers); + router[route.type](encodeURI(route.path.slice(this.rootPath.length)), ...handlers); }) }