test(utils, mdx-loader, core): improve coverage (#6303)

* test(utils, mdx-loader, core): improve coverage

* windows...

* fix
This commit is contained in:
Joshua Chen 2022-01-10 15:00:51 +08:00 committed by GitHub
parent cf265c051e
commit a79c23bc45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 841 additions and 219 deletions

View file

@ -15,7 +15,12 @@ export function normalizeUrl(rawUrls: string[]): string {
// If the first part is a plain protocol, we combine it with the next part.
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
const first = urls.shift();
urls[0] = first + urls[0];
if (first!.startsWith('file:') && urls[0].startsWith('/')) {
// Force a double slash here, else we lose the information that the next segment is an absolute path
urls[0] = `${first}//${urls[0]}`;
} else {
urls[0] = first + urls[0];
}
}
// There must be two or three slashes in the file protocol,
@ -71,7 +76,7 @@ export function normalizeUrl(rawUrls: string[]): string {
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
// Dedupe forward slashes in the entire path, avoiding protocol slashes.
str = str.replace(/([^:]\/)\/+/g, '$1');
str = str.replace(/([^:/]\/)\/+/g, '$1');
// Dedupe forward slashes at the beginning of the path.
str = str.replace(/^\/+/g, '/');