diff --git a/package-lock.json b/package-lock.json index d920dc7..25ae3c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ilc-sdk", - "version": "5.2.1", + "version": "5.2.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ilc-sdk", - "version": "5.2.1", + "version": "5.2.4", "license": "Apache-2.0", "dependencies": { "@types/url-join": "^4.0.2", diff --git a/package.json b/package.json index 2ab6420..23834f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ilc-sdk", - "version": "5.2.1", + "version": "5.2.4", "description": "SDK for app development with Isomorphic Layout Composer", "main": "dist/server/index.js", "types": "dist/server/index.d.ts", diff --git a/src/app/utils/parseAsFullyQualifiedURI.ts b/src/app/utils/parseAsFullyQualifiedURI.ts index 04a23cd..fe5d360 100644 --- a/src/app/utils/parseAsFullyQualifiedURI.ts +++ b/src/app/utils/parseAsFullyQualifiedURI.ts @@ -1,12 +1,12 @@ export default function parseAsFullyQualifiedURI(uri: string) { let origin = ''; try { + // Normalize multiple slashes to a single slash, but don't affect the initial "http://" or "https://" + uri = uri.replace(/([^:])\/{2,}/g, '$1/'); + const urlObj = new URL(uri); origin = urlObj.origin; - // Apply replacement only to the pathname, leaving the rest (search, hash) intact - urlObj.pathname = urlObj.pathname.replace(/\/{2,}/g, '/'); - uri = urlObj.pathname + urlObj.search + urlObj.hash; } catch {} diff --git a/test/app/IlcIntl.spec.ts b/test/app/IlcIntl.spec.ts index 3e2e734..eaf22cc 100644 --- a/test/app/IlcIntl.spec.ts +++ b/test/app/IlcIntl.spec.ts @@ -199,6 +199,13 @@ describe('IlcIntl', () => { }); }); + it('returns locale with normalized route when multiple slashes are present', () => { + expect(IlcIntl.parseUrl(baseConfig, '/es///tst.com')).to.eql({ + cleanUrl: '/tst.com', + locale: 'es-ES', + }); + }); + it('returns locale with default culture when no culture present in the route', () => { expect(IlcIntl.parseUrl(baseConfig, '/es-MX/tst')).to.eql({ cleanUrl: '/tst',