diff --git a/lib/internal/url.js b/lib/internal/url.js index 7f2277c474e235..3c464ffbd638f6 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1295,7 +1295,7 @@ function urlToOptions(url) { return options; } -const forwardSlashesRegEx = /\/+/g; +const forwardSlashRegEx = /\//g; function getPathFromURLWin32(url) { const hostname = url.hostname; @@ -1311,7 +1311,7 @@ function getPathFromURLWin32(url) { } } } - pathname = pathname.replace(forwardSlashesRegEx, '\\'); + pathname = pathname.replace(forwardSlashRegEx, '\\'); pathname = decodeURIComponent(pathname); if (hostname !== '') { // If hostname is set, then we have a UNC path @@ -1336,7 +1336,7 @@ function getPathFromURLPosix(url) { if (url.hostname !== '') { throw new ERR_INVALID_FILE_URL_HOST(platform); } - let pathname = url.pathname; + const pathname = url.pathname; for (let n = 0; n < pathname.length; n++) { if (pathname[n] === '%') { const third = pathname.codePointAt(n + 2) | 0x20; @@ -1347,7 +1347,6 @@ function getPathFromURLPosix(url) { } } } - pathname = pathname.replace(forwardSlashesRegEx, '/'); return decodeURIComponent(pathname); }