Skip to content

Commit 102f630

Browse files
ruromeroclaude
andcommitted
fix: filter toolchain entries in GoModulesProvider
isGoToolchainEntry() now matches both go@* and toolchain@* entries, aligning with the JS client's isSpecialGoModule() behavior. TC-3919 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c77e471 commit 102f630

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/main/java/io/github/guacsec/trustifyda/providers/GoModulesProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ private static List<String> collectAllDirectDependencies(List<String> targetLine
394394
.collect(Collectors.toList());
395395
}
396396

397-
private static boolean isGoToolchainEntry(String dependency) {
398-
// Filter out Go toolchain entries like "go@1.18", "go@1.19", etc.
399-
// These are not actual dependencies but the Go toolchain itself
400-
return dependency.startsWith("go@");
397+
static boolean isGoToolchainEntry(String dependency) {
398+
// Filter out Go toolchain entries like "go@1.18" and "toolchain@go1.21.0".
399+
// These are not actual dependencies but the Go toolchain itself.
400+
return dependency.startsWith("go@") || dependency.startsWith("toolchain@");
401401
}
402402

403403
private String buildGoModulesDependencies(Path manifestPath) {

src/test/java/io/github/guacsec/trustifyda/providers/Golang_Modules_Provider_Test.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ void Test_Golang_MvS_Logic_Disabled() throws IOException {
198198
== 1);
199199
}
200200

201+
@Test
202+
void test_isGoToolchainEntry_filters_go_and_toolchain() {
203+
// go@* entries should be filtered
204+
assertThat(GoModulesProvider.isGoToolchainEntry("go@1.18")).isTrue();
205+
assertThat(GoModulesProvider.isGoToolchainEntry("go@1.21.0")).isTrue();
206+
// toolchain@* entries should be filtered
207+
assertThat(GoModulesProvider.isGoToolchainEntry("toolchain@go1.21.0")).isTrue();
208+
assertThat(GoModulesProvider.isGoToolchainEntry("toolchain@go1.22.2")).isTrue();
209+
// normal module entries should NOT be filtered
210+
assertThat(GoModulesProvider.isGoToolchainEntry("github.com/spf13/cobra@v0.0.5")).isFalse();
211+
assertThat(GoModulesProvider.isGoToolchainEntry("golang.org/x/tools@v0.1.0")).isFalse();
212+
}
213+
201214
private String dropIgnoredKeepFormat(String s) {
202215
return s.replaceAll("goarch=\\w+&goos=\\w+&", "")
203216
.replaceAll("\"timestamp\" : \"[a-zA-Z0-9\\-\\:]+\",\n ", "");

0 commit comments

Comments
 (0)