Skip to content

Commit

Permalink
internal/span: handle escaping file URIs
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
stamblerre committed Sep 16, 2019
1 parent e45ffcd commit 64a7674
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/lsp/source/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func fileToMapper(ctx context.Context, view View, uri span.URI) (*ast.File, []Pa
if err != nil {
return nil, nil, nil, err
}
file, m, err := pkgToMapper(ctx, view, pkg, uri)
file, m, err := pkgToMapper(ctx, view, pkg, f.URI())
if err != nil {
return nil, nil, nil, err
}
Expand All @@ -109,7 +109,7 @@ func cachedFileToMapper(ctx context.Context, view View, uri span.URI) (*ast.File
if err != nil {
return nil, nil, err
}
file, m, err := pkgToMapper(ctx, view, pkg, uri)
file, m, err := pkgToMapper(ctx, view, pkg, f.URI())
if err != nil {
return nil, nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion internal/span/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ func FileURI(path string) URI {
Scheme: fileScheme,
Path: path,
}
return URI(u.String())
uri := u.String()
if unescaped, err := url.PathUnescape(uri); err == nil {
uri = unescaped
}
return URI(uri)
}

// isWindowsDrivePath returns true if the file path is of the form used by
Expand Down
1 change: 1 addition & 0 deletions internal/span/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestURI(t *testing.T) {
`c:/Go/src/bob.go`,
`/path/to/dir`,
`/a/b/c/src/bob.go`,
`c:/Go/src/bob george/george/george.go`,
} {
testPath := filepath.FromSlash(test)
expectPath := testPath
Expand Down

0 comments on commit 64a7674

Please sign in to comment.