Skip to content

Commit

Permalink
fix(common): addLeadingSlash optional group support
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharbonnier committed Jan 31, 2025
1 parent 13290e9 commit f81ce5f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/common/test/utils/shared.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
2 changes: 1 addition & 1 deletion packages/common/utils/shared.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
: '';
Expand Down

0 comments on commit f81ce5f

Please sign in to comment.