fix(v2): properly dedupe forward slashes in the entire URL path (#2405)

This commit is contained in:
Ramón Lamana 2020-03-12 15:35:30 +01:00 committed by GitHub
parent 6562a06944
commit ed5a994c7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -250,6 +250,10 @@ describe('load utils', () => {
input: ['/test/', '/docs', 'ro', 'doc1'], input: ['/test/', '/docs', 'ro', 'doc1'],
output: '/test/docs/ro/doc1', output: '/test/docs/ro/doc1',
}, },
{
input: ['/test/', '/', 'ro', 'doc1'],
output: '/test/ro/doc1',
},
{ {
input: ['', '/', 'ko', 'hello'], input: ['', '/', 'ko', 'hello'],
output: '/ko/hello', output: '/ko/hello',

View file

@ -253,8 +253,8 @@ export function normalizeUrl(rawUrls: string[]): string {
const parts = str.split('?'); const parts = str.split('?');
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&'); str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
// Dedupe forward slashes. // Dedupe forward slashes in the entire path, avoiding protocol slashes.
str = str.replace(/^\/+/, '/'); str = str.replace(/([^:]\/)\/+/g, '$1');
return str; return str;
} }