summaryrefslogtreecommitdiff
path: root/std/path
diff options
context:
space:
mode:
Diffstat (limited to 'std/path')
-rw-r--r--std/path/from_file_url_test.ts2
-rw-r--r--std/path/posix.ts4
-rw-r--r--std/path/win32.ts8
3 files changed, 9 insertions, 5 deletions
diff --git a/std/path/from_file_url_test.ts b/std/path/from_file_url_test.ts
index 7a0432f68..8fe47b27f 100644
--- a/std/path/from_file_url_test.ts
+++ b/std/path/from_file_url_test.ts
@@ -5,6 +5,7 @@ import { assertEquals } from "../testing/asserts.ts";
Deno.test("[path] fromFileUrl", function () {
assertEquals(posix.fromFileUrl(new URL("file:///home/foo")), "/home/foo");
assertEquals(posix.fromFileUrl("file:///home/foo"), "/home/foo");
+ assertEquals(posix.fromFileUrl("file:///home/foo%20bar"), "/home/foo bar");
assertEquals(posix.fromFileUrl("https://example.com/foo"), "/foo");
assertEquals(posix.fromFileUrl("file:///"), "/");
// Drive letters are supported platform-independently to align with the WHATWG
@@ -19,6 +20,7 @@ Deno.test("[path] fromFileUrl", function () {
Deno.test("[path] fromFileUrl (win32)", function () {
assertEquals(win32.fromFileUrl(new URL("file:///home/foo")), "\\home\\foo");
assertEquals(win32.fromFileUrl("file:///home/foo"), "\\home\\foo");
+ assertEquals(win32.fromFileUrl("file:///home/foo%20bar"), "\\home\\foo bar");
assertEquals(win32.fromFileUrl("https://example.com/foo"), "\\foo");
assertEquals(win32.fromFileUrl("file:///"), "\\");
assertEquals(win32.fromFileUrl("file:///c:"), "c:\\");
diff --git a/std/path/posix.ts b/std/path/posix.ts
index 3c4262203..fca7f081b 100644
--- a/std/path/posix.ts
+++ b/std/path/posix.ts
@@ -435,6 +435,6 @@ export function parse(path: string): ParsedPath {
* are ignored.
*/
export function fromFileUrl(url: string | URL): string {
- return (url instanceof URL ? url : new URL(url)).pathname
- .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/");
+ return decodeURIComponent((url instanceof URL ? url : new URL(url)).pathname
+ .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/"));
}
diff --git a/std/path/win32.ts b/std/path/win32.ts
index cf0e69537..0283f4b9c 100644
--- a/std/path/win32.ts
+++ b/std/path/win32.ts
@@ -914,7 +914,9 @@ export function parse(path: string): ParsedPath {
* are ignored.
*/
export function fromFileUrl(url: string | URL): string {
- return (url instanceof URL ? url : new URL(url)).pathname
- .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/")
- .replace(/\//g, "\\");
+ return decodeURIComponent(
+ (url instanceof URL ? url : new URL(url)).pathname
+ .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/")
+ .replace(/\//g, "\\"),
+ );
}