From cf603be24cdc92b6758c602c005f37f4d5f6c5b6 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Fri, 21 Aug 2020 14:37:06 +0100 Subject: fix: Allow isolated "%"s when parsing file URLs (#7108) --- cli/rt/06_util.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/rt/06_util.js b/cli/rt/06_util.js index 3570cb1fa..b0ed5696f 100644 --- a/cli/rt/06_util.js +++ b/cli/rt/06_util.js @@ -63,11 +63,13 @@ }); } + // Keep in sync with `fromFileUrl()` in `std/path/win32.ts`. function pathFromURLWin32(url) { let path = decodeURIComponent( url.pathname .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/") - .replace(/\//g, "\\"), + .replace(/\//g, "\\") + .replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), ); if (url.hostname != "") { // Note: The `URL` implementation guarantees that the drive letter and @@ -78,12 +80,15 @@ return path; } + // Keep in sync with `fromFileUrl()` in `std/path/posix.ts`. function pathFromURLPosix(url) { if (url.hostname !== "") { throw new TypeError(`Host must be empty.`); } - return decodeURIComponent(url.pathname); + return decodeURIComponent( + url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), + ); } function pathFromURL(pathOrUrl) { -- cgit v1.2.3