Skip to content

Commit 512b676

Browse files
stamblerreclintjedwards
authored andcommitted
internal/span: handle escaping file URIs
I wasn't sure if we should just manually construct the URI here or use the URL unescaping function. Let me know which you think is best. Updates golang/go#34270 Change-Id: Idb48fc2650d39f3e54cac141a70f356c31e303ad Reviewed-on: https://go-review.googlesource.com/c/tools/+/195618 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Ian Cottrell <[email protected]>
1 parent 052ebc8 commit 512b676

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

internal/lsp/source/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func fileToMapper(ctx context.Context, view View, uri span.URI) (*ast.File, []Pa
8686
if err != nil {
8787
return nil, nil, nil, err
8888
}
89-
file, m, err := pkgToMapper(ctx, view, pkg, uri)
89+
file, m, err := pkgToMapper(ctx, view, pkg, f.URI())
9090
if err != nil {
9191
return nil, nil, nil, err
9292
}
@@ -109,7 +109,7 @@ func cachedFileToMapper(ctx context.Context, view View, uri span.URI) (*ast.File
109109
if err != nil {
110110
return nil, nil, err
111111
}
112-
file, m, err := pkgToMapper(ctx, view, pkg, uri)
112+
file, m, err := pkgToMapper(ctx, view, pkg, f.URI())
113113
if err != nil {
114114
return nil, nil, err
115115
}

internal/span/uri.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ func FileURI(path string) URI {
124124
Scheme: fileScheme,
125125
Path: path,
126126
}
127-
return URI(u.String())
127+
uri := u.String()
128+
if unescaped, err := url.PathUnescape(uri); err == nil {
129+
uri = unescaped
130+
}
131+
return URI(uri)
128132
}
129133

130134
// isWindowsDrivePath returns true if the file path is of the form used by

internal/span/uri_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestURI(t *testing.T) {
2323
`c:/Go/src/bob.go`,
2424
`/path/to/dir`,
2525
`/a/b/c/src/bob.go`,
26+
`c:/Go/src/bob george/george/george.go`,
2627
} {
2728
testPath := filepath.FromSlash(test)
2829
expectPath := testPath

0 commit comments

Comments
 (0)