summaryrefslogtreecommitdiff
path: root/std/path/posix.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-07-30 23:37:26 +0100
committerGitHub <noreply@github.com>2020-07-30 18:37:26 -0400
commit6e7208bec2911ac0d1729f334fc90bc50b8f9203 (patch)
tree1361d123ca43e66bb0725295b59a1b5075108517 /std/path/posix.ts
parent0da4779b178a0c97925c1ef5589d0f24a37f4501 (diff)
fix(cli/rt): Fix file URL to path conversion on Windows (#6920)
Diffstat (limited to 'std/path/posix.ts')
-rw-r--r--std/path/posix.ts10
1 files changed, 5 insertions, 5 deletions
diff --git a/std/path/posix.ts b/std/path/posix.ts
index fca7f081b..afbc9303f 100644
--- a/std/path/posix.ts
+++ b/std/path/posix.ts
@@ -430,11 +430,11 @@ export function parse(path: string): ParsedPath {
/** Converts a file URL to a path string.
*
* fromFileUrl("file:///home/foo"); // "/home/foo"
- *
- * Note that non-file URLs are treated as file URLs and irrelevant components
- * are ignored.
*/
export function fromFileUrl(url: string | URL): string {
- return decodeURIComponent((url instanceof URL ? url : new URL(url)).pathname
- .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/"));
+ url = url instanceof URL ? url : new URL(url);
+ if (url.protocol != "file:") {
+ throw new TypeError("Must be a file URL.");
+ }
+ return decodeURIComponent(url.pathname);
}