Skip to content

Commit

Permalink
go1.18: Preserve trailing tabs while massaging go version -m output (
Browse files Browse the repository at this point in the history
…ko-build#668)

* go1.18 compatibility: Add workaround for local replace directives

* Fix actual bug where trailing tabs were stripped
  • Loading branch information
tstromberg authored Mar 22, 2022
1 parent 327a88f commit cefd28f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/sbom/mod_1.18.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type BuildInfo debug.BuildInfo

func ParseBuildInfo(data string) (*BuildInfo, error) {
dbi, err := debug.ParseBuildInfo(string(data))
dbi, err := debug.ParseBuildInfo(data)
if err != nil {
return nil, fmt.Errorf("parsing build info: %w", err)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"fmt"
"strings"
"unicode"
)

// massageGoModVersion massages the output of `go version -m` into a form that
Expand All @@ -41,7 +42,8 @@ func massageGoVersionM(b []byte) ([]byte, error) {
return nil, fmt.Errorf("malformed input: %w", err)
}
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
// NOTE: debug.ParseBuildInfo relies on trailing tabs.
line := strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace)
fmt.Fprintln(&out, line)
}
if err := scanner.Err(); err != nil {
Expand Down

0 comments on commit cefd28f

Please sign in to comment.