diff --git a/packages/cozy-client/src/helpers/urlHelper.js b/packages/cozy-client/src/helpers/urlHelper.js index 171e7e49ee..6c7c77dbca 100644 --- a/packages/cozy-client/src/helpers/urlHelper.js +++ b/packages/cozy-client/src/helpers/urlHelper.js @@ -44,7 +44,7 @@ export const generateWebLink = ({ .split('.') .map((x, i) => (i === 0 ? x + '-' + slug : x)) .join('.') - url.pathname = pathname + url.pathname = ensureFirstSlash(pathname) url.hash = ensureFirstSlash(hash) for (const [param, value] of searchParams) { diff --git a/packages/cozy-client/src/helpers/urlHelper.spec.js b/packages/cozy-client/src/helpers/urlHelper.spec.js index 3e2e4ba5cb..2ece4a46d6 100644 --- a/packages/cozy-client/src/helpers/urlHelper.spec.js +++ b/packages/cozy-client/src/helpers/urlHelper.spec.js @@ -40,6 +40,18 @@ describe('generateWebLink', () => { }) ).toEqual(`https://drive.alice.cozy.tools/public/#/files/432432`) }) + + it('should handle undefined pathname', () => { + expect( + generateWebLink({ + cozyUrl: 'https://alice.cozy.tools', + pathname: undefined, + hash: 'files/432432', + slug: 'drive', + subDomainType: 'nested' + }) + ).toEqual(`https://drive.alice.cozy.tools/#/files/432432`) + }) }) describe('deconstructWebLink', () => {