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 <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-09-16 10:49:42 -04:00
parent e45ffcd953
commit 64a767472a
3 changed files with 8 additions and 3 deletions

View File

@ -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
}
@ -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
}

View File

@ -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

View File

@ -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