Skip to content

Commit 88f3c62

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 7a9acb0 commit 88f3c62

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

internal/span/uri.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ func filename(uri URI) (string, error) {
5454
}
5555

5656
func URIFromURI(s string) URI {
57-
if !strings.HasPrefix(s, "file:///") {
57+
if !strings.HasPrefix(s, "file://") {
5858
return URI(s)
5959
}
6060

61+
if !strings.HasPrefix(s, "file:///") {
62+
// VS Code sends URLs with only two slashes, which are invalid. golang/go#39789.
63+
s = "file:///" + s[len("file://"):]
64+
}
6165
// Even though the input is a URI, it may not be in canonical form. VS Code
6266
// in particular over-escapes :, @, etc. Unescape and re-encode to canonicalize.
6367
path, err := url.PathUnescape(s[len("file://"):])

internal/span/uri_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func TestURIFromURI(t *testing.T) {
9898
wantFile: `/`,
9999
wantURI: span.URI(`file:///`),
100100
},
101+
{
102+
inputURI: `file://wsl%24/Ubuntu/home/wdcui/repo/VMEnclaves/cvm-runtime`,
103+
wantFile: `/wsl$/Ubuntu/home/wdcui/repo/VMEnclaves/cvm-runtime`,
104+
wantURI: span.URI(`file:///wsl$/Ubuntu/home/wdcui/repo/VMEnclaves/cvm-runtime`),
105+
},
101106
} {
102107
got := span.URIFromURI(test.inputURI)
103108
if got != test.wantURI {

0 commit comments

Comments
 (0)