diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7135dc3..f642f8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: - run: npm run build - run: npm run coverage - if: matrix.node-version == '20.x' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: Code coverage path: coverage/ diff --git a/src/app/utils/parseAsFullyQualifiedURI.ts b/src/app/utils/parseAsFullyQualifiedURI.ts index 1db6183..04a23cd 100644 --- a/src/app/utils/parseAsFullyQualifiedURI.ts +++ b/src/app/utils/parseAsFullyQualifiedURI.ts @@ -3,6 +3,10 @@ export default function parseAsFullyQualifiedURI(uri: string) { try { 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 b38257d..3e2e734 100644 --- a/test/app/IlcIntl.spec.ts +++ b/test/app/IlcIntl.spec.ts @@ -148,6 +148,12 @@ describe('IlcIntl', () => { expect(IlcIntl.localizeUrl(baseConfig, 'http://tst.com/', { locale: 'es-ES' })).to.eq('http://tst.com/es/'); }); + it('handles multiple slashes in the URL correctly', () => { + expect(IlcIntl.localizeUrl(baseConfig, 'http://tst.com/es///google.com', { locale: 'es-ES' })).to.eq( + 'http://tst.com/es/google.com', + ); + }); + it('handles special cases', () => { expect(IlcIntl.localizeUrl(baseConfig, '/')).to.equal('/'); expect(IlcIntl.localizeUrl(baseConfig, '/', { locale: 'es-ES' })).to.equal('/es/'); @@ -211,6 +217,20 @@ describe('IlcIntl', () => { }); }); + it('handles multiple slashes in the URL correctly', () => { + expect(IlcIntl.parseUrl(baseConfig, 'http://tst.com/es///google.com')).to.eql({ + cleanUrl: 'http://tst.com/google.com', + locale: 'es-ES', + }); + }); + + it('handles URL with multiple slashes and a port', () => { + expect(IlcIntl.parseUrl(baseConfig, 'http://tst.com:3000/es///google.com')).to.eql({ + cleanUrl: 'http://tst.com:3000/google.com', + locale: 'es-ES', + }); + }); + it('handles corner cases', () => { expect(IlcIntl.parseUrl(baseConfig, '/')).to.eql({ cleanUrl: '/',