Skip to content

Commit

Permalink
Merge pull request #2 from fgma/bugfix_uri_on_windows
Browse files Browse the repository at this point in the history
fix URI handling on windows
  • Loading branch information
neilpa authored Mar 11, 2020
2 parents faf5a63 + 52ef91a commit 86914bc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,22 @@ func fileUri(path string) string {
if err != nil {
log.Fatalf("%s: %s", path, err)
}
return "file://" + abs

uri := "file://"

if runtime.GOOS == "windows" {
// This is not formally correct for all corner cases in windows
// file handling but should work for all standard cases. See:
// https://docs.microsoft.com/en-us/archive/blogs/ie/file-uris-in-windows
uri = uri + "/" + strings.ReplaceAll(
strings.ReplaceAll(abs, "\\", "/"),
" ", "%20",
)
} else {
uri = uri + abs
}

return uri
}

// glob is a wrapper that also resolves `~` since we may be skipping
Expand Down

0 comments on commit 86914bc

Please sign in to comment.