summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-08-21 14:37:06 +0100
committerGitHub <noreply@github.com>2020-08-21 15:37:06 +0200
commitcf603be24cdc92b6758c602c005f37f4d5f6c5b6 (patch)
tree4e0d0212a44ad8af3a777cebf65bf266e5c06523 /std
parentfd83df7cdb983030ba111a1e19ad6c9ef5eb6128 (diff)
fix: Allow isolated "%"s when parsing file URLs (#7108)
Diffstat (limited to 'std')
-rw-r--r--std/path/from_file_url_test.ts2
-rw-r--r--std/path/posix.ts4
-rw-r--r--std/path/win32.ts3
3 files changed, 7 insertions, 2 deletions
diff --git a/std/path/from_file_url_test.ts b/std/path/from_file_url_test.ts
index b1a1af99c..e69310a37 100644
--- a/std/path/from_file_url_test.ts
+++ b/std/path/from_file_url_test.ts
@@ -7,6 +7,7 @@ Deno.test("[path] fromFileUrl", function () {
assertEquals(posix.fromFileUrl("file:///"), "/");
assertEquals(posix.fromFileUrl("file:///home/foo"), "/home/foo");
assertEquals(posix.fromFileUrl("file:///home/foo%20bar"), "/home/foo bar");
+ assertEquals(posix.fromFileUrl("file:///%"), "/%");
assertEquals(posix.fromFileUrl("file://localhost/foo"), "/foo");
assertEquals(posix.fromFileUrl("file:///C:"), "/C:");
assertEquals(posix.fromFileUrl("file:///C:/"), "/C:/");
@@ -29,6 +30,7 @@ Deno.test("[path] fromFileUrl (win32)", function () {
assertEquals(win32.fromFileUrl("file:///"), "\\");
assertEquals(win32.fromFileUrl("file:///home/foo"), "\\home\\foo");
assertEquals(win32.fromFileUrl("file:///home/foo%20bar"), "\\home\\foo bar");
+ assertEquals(win32.fromFileUrl("file:///%"), "\\%");
assertEquals(win32.fromFileUrl("file://localhost/foo"), "\\\\localhost\\foo");
assertEquals(win32.fromFileUrl("file:///C:"), "C:\\");
assertEquals(win32.fromFileUrl("file:///C:/"), "C:\\");
diff --git a/std/path/posix.ts b/std/path/posix.ts
index afbc9303f..33b94a916 100644
--- a/std/path/posix.ts
+++ b/std/path/posix.ts
@@ -436,5 +436,7 @@ export function fromFileUrl(url: string | URL): string {
if (url.protocol != "file:") {
throw new TypeError("Must be a file URL.");
}
- return decodeURIComponent(url.pathname);
+ return decodeURIComponent(
+ url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
+ );
}
diff --git a/std/path/win32.ts b/std/path/win32.ts
index eed1cbdb8..19b29a6b9 100644
--- a/std/path/win32.ts
+++ b/std/path/win32.ts
@@ -919,7 +919,8 @@ export function fromFileUrl(url: string | URL): string {
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