Skip to content

Commit cac23d2

Browse files
Fix stdlib detection when goroot and gopath share the same prefix (#148)
This fixes #38.
1 parent 14362dc commit cac23d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

licenses/library.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,10 @@ func isStdLib(pkg *packages.Package) bool {
286286
if len(pkg.GoFiles) == 0 {
287287
return false
288288
}
289-
return strings.HasPrefix(pkg.GoFiles[0], build.Default.GOROOT)
289+
prefix := build.Default.GOROOT
290+
sep := string(filepath.Separator)
291+
if !strings.HasSuffix(prefix, sep) {
292+
prefix += sep
293+
}
294+
return strings.HasPrefix(pkg.GoFiles[0], prefix)
290295
}

0 commit comments

Comments
 (0)