]> Cypherpunks repositories - gostls13.git/commit
cmd/go: open correct path when loading embeds from root directory
authortenkoh <tenkoh.go@gmail.com>
Wed, 30 Mar 2022 06:30:19 +0000 (15:30 +0900)
committerGopher Robot <gobot@golang.org>
Tue, 12 Apr 2022 16:47:01 +0000 (16:47 +0000)
commit5bf6c97e76c721242a9b064950cd901c33f6f0b9
tree775ab931e72e7248c50f638a92a0f37b027bf1b8
parent8f1d5d0a41840c1e6b36c94d493af8aae1302fd0
cmd/go: open correct path when loading embeds from root directory

The existing implementation of `load.resolveEmbed`
uses an expression like `path[len(pkgdir)+1:]`.
Though the `+1` is intended to remove a prefix slash,
the expression returns an incorrect path when `pkgdir`
is "/". (ex.: when removing "/" from "/foo", want "foo",
but got "oo")

It seems that `str.TrimFilePathPrefix` would solve
the problem, but the function contains the same bug.

So, this commit fixes `str.TrimFilePathPrefix` then
applies it to `load.resolveEmbed` to solve the issue.
The fix is quite simple. First, remove prefix. Then
check whether the remained first letter is equal to
`filepath.Separator`. If so, remove it then return.

Fixed #49570

Change-Id: I26ab727ee4dfcbf51ed9bd0a573957ced2154515
Reviewed-on: https://go-review.googlesource.com/c/go/+/396694
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/str/path.go
src/cmd/go/internal/str/str_test.go