internal/span: handle file URLs with two slashes
Correct file URLs should have three slashes: two for the protocol
(file://) and one for the beginning of the path. Perhaps unsurprisingly,
VS Code is sending us URLs with only two. Add the third.
Fixes golang/go#39789
Change-Id: I922b3adf1d5980991a43229d952d77fecaf1366b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239743
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/span/uri.go b/internal/span/uri.go
index f9f7760..78e71fe 100644
--- a/internal/span/uri.go
+++ b/internal/span/uri.go
@@ -54,10 +54,14 @@
}
func URIFromURI(s string) URI {
- if !strings.HasPrefix(s, "file:///") {
+ if !strings.HasPrefix(s, "file://") {
return URI(s)
}
+ if !strings.HasPrefix(s, "file:///") {
+ // VS Code sends URLs with only two slashes, which are invalid. golang/go#39789.
+ s = "file:///" + s[len("file://"):]
+ }
// Even though the input is a URI, it may not be in canonical form. VS Code
// in particular over-escapes :, @, etc. Unescape and re-encode to canonicalize.
path, err := url.PathUnescape(s[len("file://"):])
diff --git a/internal/span/uri_test.go b/internal/span/uri_test.go
index cea74aa..260f948 100644
--- a/internal/span/uri_test.go
+++ b/internal/span/uri_test.go
@@ -98,6 +98,11 @@
wantFile: `/`,
wantURI: span.URI(`file:///`),
},
+ {
+ inputURI: `file://wsl%24/Ubuntu/home/wdcui/repo/VMEnclaves/cvm-runtime`,
+ wantFile: `/wsl$/Ubuntu/home/wdcui/repo/VMEnclaves/cvm-runtime`,
+ wantURI: span.URI(`file:///wsl$/Ubuntu/home/wdcui/repo/VMEnclaves/cvm-runtime`),
+ },
} {
got := span.URIFromURI(test.inputURI)
if got != test.wantURI {