mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 00:21:05 -05:00
fix(std/path): Percent-decode in fromFileUrl() (#6913)
This commit is contained in:
parent
1b60840f28
commit
6afe7bbd39
3 changed files with 9 additions and 5 deletions
|
@ -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:\\");
|
||||
|
|
|
@ -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/"));
|
||||
}
|
||||
|
|
|
@ -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, "\\"),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue