Skip to content

Commit

Permalink
buildinfo: fix parsing when windows paths are used
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Jones committed Jan 26, 2021
1 parent ac1fa28 commit 1d6c981
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/buildinfo/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ func Parse(info string) ([]model.BuildInfo, error) {

// start of new build info output
if !strings.HasPrefix(l, "\t") {
parts := strings.SplitN(l, ":", 2)
if len(parts) != 2 {
parts := strings.Split(l, ":")
if len(parts) < 2 {
return nil, fmt.Errorf("invalid version line: %s", l)
}
version := strings.TrimSpace(parts[1])
version := strings.TrimSpace(parts[len(parts)-1])
path := strings.Join(parts[:len(parts)-1], ":")
switch {
case version == "not executable file":
return nil, fmt.Errorf("%s is not an executable", parts[0])
Expand All @@ -43,7 +44,7 @@ func Parse(info string) ([]model.BuildInfo, error) {
if current.Path != "" {
results = append(results, current)
}
current = model.BuildInfo{Path: parts[0]}
current = model.BuildInfo{Path: path}
continue
}

Expand Down
21 changes: 21 additions & 0 deletions internal/buildinfo/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ func TestParse(t *testing.T) {
},
},
},
{
name: "windows basic single binary input",
input: `C:\lichen.exe: go1.14.4
path github.com/uw-labs/lichen
mod github.com/uw-labs/lichen (devel)
dep github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
`,
expected: []model.BuildInfo{
{
Path: `C:\lichen.exe`,
PackagePath: "github.com/uw-labs/lichen",
ModulePath: "github.com/uw-labs/lichen",
ModuleRefs: []model.ModuleReference{
{
Path: "github.com/cpuguy83/go-md2man/v2",
Version: "v2.0.0-20190314233015-f79a8a8ca69d",
},
},
},
},
},
{
name: "not executable file",
input: `/tmp/lichen: not executable file`,
Expand Down

0 comments on commit 1d6c981

Please sign in to comment.