From ece4625b0560c9d87b254da05f2f3fd8c57521f4 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 30 Nov 2024 01:26:27 +1100 Subject: [PATCH] [8.x] Fix Code Scanning Alert #1292 (#202125) (#202292) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [Fix Code Scanning Alert #1292 (#202125)](https://github.com/elastic/kibana/pull/202125) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Alejandro Fernández Haro --- packages/kbn-router-to-openapispec/src/util.test.ts | 2 ++ packages/kbn-router-to-openapispec/src/util.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/kbn-router-to-openapispec/src/util.test.ts b/packages/kbn-router-to-openapispec/src/util.test.ts index e3011aa1a5a73..ee34976e47152 100644 --- a/packages/kbn-router-to-openapispec/src/util.test.ts +++ b/packages/kbn-router-to-openapispec/src/util.test.ts @@ -117,10 +117,12 @@ describe('assignToPaths', () => { assignToPaths(paths, '/foo', {}); assignToPaths(paths, '/bar/{id?}', {}); assignToPaths(paths, '/bar/file/{path*}', {}); + assignToPaths(paths, '/bar/file/{path*}/{id?}', {}); expect(paths).toEqual({ '/foo': {}, '/bar/{id}': {}, '/bar/file/{path}': {}, + '/bar/file/{path}/{id}': {}, }); }); }); diff --git a/packages/kbn-router-to-openapispec/src/util.ts b/packages/kbn-router-to-openapispec/src/util.ts index 1088259e73d05..61c69caf538f9 100644 --- a/packages/kbn-router-to-openapispec/src/util.ts +++ b/packages/kbn-router-to-openapispec/src/util.ts @@ -132,7 +132,7 @@ export const assignToPaths = ( path: string, pathObject: OpenAPIV3.PathItemObject ): void => { - const pathName = path.replace(/[\?\*]/, ''); + const pathName = path.replace(/[\?\*]/g, ''); paths[pathName] = { ...paths[pathName], ...pathObject }; };