diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-07-30 23:37:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 18:37:26 -0400 |
commit | 6e7208bec2911ac0d1729f334fc90bc50b8f9203 (patch) | |
tree | 1361d123ca43e66bb0725295b59a1b5075108517 /std/path/from_file_url_test.ts | |
parent | 0da4779b178a0c97925c1ef5589d0f24a37f4501 (diff) |
fix(cli/rt): Fix file URL to path conversion on Windows (#6920)
Diffstat (limited to 'std/path/from_file_url_test.ts')
-rw-r--r-- | std/path/from_file_url_test.ts | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/std/path/from_file_url_test.ts b/std/path/from_file_url_test.ts index 8fe47b27f..b1a1af99c 100644 --- a/std/path/from_file_url_test.ts +++ b/std/path/from_file_url_test.ts @@ -1,31 +1,49 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { posix, win32 } from "./mod.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../testing/asserts.ts"; Deno.test("[path] fromFileUrl", function () { assertEquals(posix.fromFileUrl(new URL("file:///home/foo")), "/home/foo"); + assertEquals(posix.fromFileUrl("file:///"), "/"); 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 - // URL specification. - assertEquals(posix.fromFileUrl("file:///c:"), "c:/"); - assertEquals(posix.fromFileUrl("file:///c:/"), "c:/"); - assertEquals(posix.fromFileUrl("file:///C:/"), "C:/"); - assertEquals(posix.fromFileUrl("file:///C:/Users/"), "C:/Users/"); + assertEquals(posix.fromFileUrl("file://localhost/foo"), "/foo"); + assertEquals(posix.fromFileUrl("file:///C:"), "/C:"); + assertEquals(posix.fromFileUrl("file:///C:/"), "/C:/"); + assertEquals(posix.fromFileUrl("file:///C:/Users/"), "/C:/Users/"); assertEquals(posix.fromFileUrl("file:///C:foo/bar"), "/C:foo/bar"); + assertThrows( + () => posix.fromFileUrl("http://localhost/foo"), + TypeError, + "Must be a file URL.", + ); + assertThrows( + () => posix.fromFileUrl("abcd://localhost/foo"), + TypeError, + "Must be a file URL.", + ); }); Deno.test("[path] fromFileUrl (win32)", function () { assertEquals(win32.fromFileUrl(new URL("file:///home/foo")), "\\home\\foo"); + assertEquals(win32.fromFileUrl("file:///"), "\\"); 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:\\"); - assertEquals(win32.fromFileUrl("file:///c:/"), "c:\\"); + assertEquals(win32.fromFileUrl("file://localhost/foo"), "\\\\localhost\\foo"); + assertEquals(win32.fromFileUrl("file:///C:"), "C:\\"); assertEquals(win32.fromFileUrl("file:///C:/"), "C:\\"); + // Drop the hostname if a drive letter is parsed. + assertEquals(win32.fromFileUrl("file://localhost/C:/"), "C:\\"); assertEquals(win32.fromFileUrl("file:///C:/Users/"), "C:\\Users\\"); assertEquals(win32.fromFileUrl("file:///C:foo/bar"), "\\C:foo\\bar"); + assertThrows( + () => win32.fromFileUrl("http://localhost/foo"), + TypeError, + "Must be a file URL.", + ); + assertThrows( + () => win32.fromFileUrl("abcd://localhost/foo"), + TypeError, + "Must be a file URL.", + ); }); |