From 661d897f23e65f0634e00feefb4bd5bd526007fd Mon Sep 17 00:00:00 2001 From: fgma Date: Wed, 11 Mar 2020 18:32:28 +0100 Subject: [PATCH 1/2] fix URI handling on windows --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 30aa9c2..c7b6d56 100644 --- a/main.go +++ b/main.go @@ -183,7 +183,19 @@ func fileUri(path string) string { if err != nil { log.Fatalf("%s: %s", path, err) } - return "file://" + abs + + uri := "file://" + + if runtime.GOOS == "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 From 52ef91a9e3fdc47c181624265c23cfc5e1395b9b Mon Sep 17 00:00:00 2001 From: Neil Pankey Date: Wed, 11 Mar 2020 13:05:40 -0700 Subject: [PATCH 2/2] Link to what's required for full Windows URI support --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index c7b6d56..24bc40f 100644 --- a/main.go +++ b/main.go @@ -187,6 +187,9 @@ func fileUri(path string) string { 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",