summaryrefslogtreecommitdiff
path: root/std/path/posix.ts
diff options
context:
space:
mode:
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);
}