Skip to content

Commit

Permalink
feat(URL): Support drive letters for file URLs on Windows (denoland/d…
Browse files Browse the repository at this point in the history
…eno#5074)

refactor: Parse URLs more sequentially. This makes it easier to change matching behaviour depending on the protocol.
fix: Fail when a host isn't given for certain protocols.
fix: Convert back-slashes info forward-slashes.
  • Loading branch information
nayeemrmn authored and caspervonb committed Jan 31, 2021
1 parent 013128e commit fea024c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion path/from_file_url_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Deno.test("[path] fromFileUrl (win32)", function () {
// assertEquals(path.win32.fromFileUrl("file:////server"), "\\");
// assertEquals(path.win32.fromFileUrl("file:////server/file"), "\\file");
assertEquals(path.win32.fromFileUrl("file:///c"), "\\c");
assertEquals(path.win32.fromFileUrl("file:///c:"), "\\c:");
assertEquals(path.win32.fromFileUrl("file:///c:"), "c:\\");
assertEquals(path.win32.fromFileUrl("file:///c:/"), "c:\\");
assertEquals(path.win32.fromFileUrl("file:///C:/"), "C:\\");
assertEquals(path.win32.fromFileUrl("file:///C:/Users/"), "C:\\Users\\");
Expand Down
2 changes: 1 addition & 1 deletion path/win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,6 @@ export function parse(path: string): ParsedPath {
*/
export function fromFileUrl(url: string | URL): string {
return new URL(url).pathname
.replace(/^\/(?=[A-Za-z]:\/)/, "")
.replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/")
.replace(/\//g, "\\");
}

0 comments on commit fea024c

Please sign in to comment.