mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
fix(cli): strings shouldn't be interpreted as file URLs (#6412)
This commit is contained in:
parent
70463bac7d
commit
175867ab76
2 changed files with 16 additions and 14 deletions
|
@ -110,14 +110,9 @@ function pathFromURLPosix(url: URL): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pathFromURL(pathOrUrl: string | URL): string {
|
export function pathFromURL(pathOrUrl: string | URL): string {
|
||||||
if (typeof pathOrUrl == "string") {
|
|
||||||
try {
|
|
||||||
pathOrUrl = new URL(pathOrUrl);
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
if (pathOrUrl instanceof URL) {
|
if (pathOrUrl instanceof URL) {
|
||||||
if (pathOrUrl.protocol != "file:") {
|
if (pathOrUrl.protocol != "file:") {
|
||||||
throw new TypeError("Must be a path string or file URL.");
|
throw new TypeError("Must be a file URL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return build.os == "windows"
|
return build.os == "windows"
|
||||||
|
|
|
@ -6,20 +6,27 @@ const { pathFromURL } = Deno[Deno.internal];
|
||||||
unitTest(
|
unitTest(
|
||||||
{ ignore: Deno.build.os === "windows" },
|
{ ignore: Deno.build.os === "windows" },
|
||||||
function pathFromURLPosix(): void {
|
function pathFromURLPosix(): void {
|
||||||
assertEquals(pathFromURL("file:///test/directory"), "/test/directory");
|
assertEquals(
|
||||||
assertEquals(pathFromURL("file:///space_ .txt"), "/space_ .txt");
|
pathFromURL(new URL("file:///test/directory")),
|
||||||
assertThrows(() => pathFromURL("file://host/test/directory"));
|
"/test/directory"
|
||||||
assertThrows(() => pathFromURL("https://deno.land/welcome.ts"));
|
);
|
||||||
|
assertEquals(pathFromURL(new URL("file:///space_ .txt")), "/space_ .txt");
|
||||||
|
assertThrows(() => pathFromURL(new URL("https://deno.land/welcome.ts")));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
unitTest(
|
unitTest(
|
||||||
{ ignore: Deno.build.os !== "windows" },
|
{ ignore: Deno.build.os !== "windows" },
|
||||||
function pathFromURLWin32(): void {
|
function pathFromURLWin32(): void {
|
||||||
assertEquals(pathFromURL("file:///c:/windows/test"), "c:\\windows\\test");
|
assertEquals(
|
||||||
assertEquals(pathFromURL("file:///c:/space_ .txt"), "c:\\space_ .txt");
|
pathFromURL(new URL("file:///c:/windows/test")),
|
||||||
assertThrows(() => pathFromURL("file:///thing/test"));
|
"c:\\windows\\test"
|
||||||
assertThrows(() => pathFromURL("https://deno.land/welcome.ts"));
|
);
|
||||||
|
assertEquals(
|
||||||
|
pathFromURL(new URL("file:///c:/space_ .txt")),
|
||||||
|
"c:\\space_ .txt"
|
||||||
|
);
|
||||||
|
assertThrows(() => pathFromURL(new URL("https://deno.land/welcome.ts")));
|
||||||
/* TODO(ry) Add tests for these situations
|
/* TODO(ry) Add tests for these situations
|
||||||
* ampersand_&.tx file:///D:/weird_names/ampersand_&.txt
|
* ampersand_&.tx file:///D:/weird_names/ampersand_&.txt
|
||||||
* at_@.txt file:///D:/weird_names/at_@.txt
|
* at_@.txt file:///D:/weird_names/at_@.txt
|
||||||
|
|
Loading…
Add table
Reference in a new issue