From f81ce5f7745b1d2d9bc0a986d038040a3dbc50bd Mon Sep 17 00:00:00 2001 From: david Date: Fri, 31 Jan 2025 15:36:56 +0100 Subject: [PATCH] fix(common): addLeadingSlash optional group support --- packages/common/test/utils/shared.utils.spec.ts | 2 ++ packages/common/utils/shared.utils.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/common/test/utils/shared.utils.spec.ts b/packages/common/test/utils/shared.utils.spec.ts index 391838d6580..d7c0de0eac3 100644 --- a/packages/common/test/utils/shared.utils.spec.ts +++ b/packages/common/test/utils/shared.utils.spec.ts @@ -117,9 +117,11 @@ describe('Shared utils', () => { describe('addLeadingSlash', () => { it('should return the validated path ("add / if not exists")', () => { expect(addLeadingSlash('nope')).to.be.eql('/nope'); + expect(addLeadingSlash('{:nope}')).to.be.eql('/{:nope}'); }); it('should return the same path', () => { expect(addLeadingSlash('/nope')).to.be.eql('/nope'); + expect(addLeadingSlash('{/:nope}')).to.be.eql('{/:nope}'); }); it('should return empty path', () => { expect(addLeadingSlash('')).to.be.eql(''); diff --git a/packages/common/utils/shared.utils.ts b/packages/common/utils/shared.utils.ts index c2582dc0ff5..e936c8d2448 100644 --- a/packages/common/utils/shared.utils.ts +++ b/packages/common/utils/shared.utils.ts @@ -25,7 +25,7 @@ export const isPlainObject = (fn: any): fn is object => { export const addLeadingSlash = (path?: string): string => path && typeof path === 'string' - ? path.charAt(0) !== '/' + ? path.charAt(0) !== '/' && path.substring(0, 2) !== '{/' ? '/' + path : path : '';