diff --git a/main.go b/main.go index 30aa9c2..24bc40f 100644 --- a/main.go +++ b/main.go @@ -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