1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-12 18:42:18 -05:00
denoland-deno/std/path/from_file_url_test.ts
Nayeem Rahman a8f74aa381
fix: Improve URL compatibility (#6807)
- Fix protocol regex.
- Truncate repeated leading slashes in file paths.
- Make drive letter support platform-independent.
- Drop the hostname if a drive letter is parsed.
- Fix drive letter normalization and basing.
- Allow basing over the host.
- Fix same-protocol basing.
- Remove Windows UNC path support.
- Reverts #6418. This is non-standard. Wouldn't be too much of a problem but it 
   makes other parts of the spec hard to realize.
2020-07-23 21:37:11 -04:00

29 lines
1.5 KiB
TypeScript

// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { posix, win32 } from "./mod.ts";
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("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:///C:foo/bar"), "/C:foo/bar");
});
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("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:///C:/"), "C:\\");
assertEquals(win32.fromFileUrl("file:///C:/Users/"), "C:\\Users\\");
assertEquals(win32.fromFileUrl("file:///C:foo/bar"), "\\C:foo\\bar");
});