mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 02:37:59 +02:00
fix(v2): properly dedupe forward slashes in the entire URL path (#2405)
This commit is contained in:
parent
6562a06944
commit
ed5a994c7e
2 changed files with 6 additions and 2 deletions
|
@ -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',
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue