Skip to content

Commit

Permalink
Fix stdlib detection when goroot and gopath share the same prefix (#148)
Browse files Browse the repository at this point in the history
This fixes #38.
  • Loading branch information
jingyuanliang authored Sep 14, 2022
1 parent 14362dc commit cac23d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion licenses/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,10 @@ func isStdLib(pkg *packages.Package) bool {
if len(pkg.GoFiles) == 0 {
return false
}
return strings.HasPrefix(pkg.GoFiles[0], build.Default.GOROOT)
prefix := build.Default.GOROOT
sep := string(filepath.Separator)
if !strings.HasSuffix(prefix, sep) {
prefix += sep
}
return strings.HasPrefix(pkg.GoFiles[0], prefix)
}

0 comments on commit cac23d2

Please sign in to comment.