Skip to content

Commit fbd733c

Browse files
committed
fix: trim the suffix from toolchains
1 parent 1ab3920 commit fbd733c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

extractor/filesystem/language/golang/gomod/gomod.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
131131

132132
// Give the toolchain version priority, if present
133133
if parsedLockfile.Toolchain != nil && parsedLockfile.Toolchain.Name != "" {
134+
version, _, _ := strings.Cut(parsedLockfile.Toolchain.Name, "-")
135+
134136
packages[mapKey{name: "stdlib"}] = &extractor.Inventory{
135137
Name: "stdlib",
136-
Version: strings.TrimPrefix(parsedLockfile.Toolchain.Name, "go"),
138+
Version: strings.TrimPrefix(version, "go"),
137139
Locations: []string{input.Path},
138140
}
139141
}

extractor/filesystem/language/golang/gomod/gomod_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ func TestExtractor_Extract(t *testing.T) {
138138
},
139139
},
140140
},
141+
{
142+
Name: "toolchain with suffix",
143+
InputConfig: extracttest.ScanInputMockConfig{
144+
Path: "testdata/toolchain-with-suffix.mod",
145+
},
146+
WantInventory: []*extractor.Inventory{
147+
{
148+
Name: "github.com/BurntSushi/toml",
149+
Version: "1.0.0",
150+
Locations: []string{"testdata/toolchain-with-suffix.mod"},
151+
},
152+
{
153+
Name: "stdlib",
154+
Version: "1.23.6",
155+
Locations: []string{"testdata/toolchain-with-suffix.mod"},
156+
},
157+
},
158+
},
141159
{
142160
Name: "indirect packages",
143161
InputConfig: extracttest.ScanInputMockConfig{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module my-library
2+
3+
go 1.23.5
4+
5+
toolchain go1.23.6-xyz
6+
7+
require (
8+
github.com/BurntSushi/toml v1.0.0
9+
)

0 commit comments

Comments
 (0)