Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

3030 license declared spdx correction #3461

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions syft/format/common/spdxhelpers/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,15 @@ func toOtherLicenses(catalog *pkg.Collection) []*spdx.OtherLicense {
if l.Value != "" {
licenses[l.ID] = l
}
if l.ID != "" && isSingularLicenseRef(l.ID) {
if l.ID != "" && isLicenseRef(l.ID) {
licenses[l.ID] = l
}
}
for _, l := range concludedLicenses {
if l.Value != "" {
licenses[l.ID] = l
}
if l.ID != "" && isSingularLicenseRef(l.ID) {
if l.ID != "" && isLicenseRef(l.ID) {
licenses[l.ID] = l
}
}
Expand Down Expand Up @@ -762,13 +762,12 @@ func toOtherLicenses(catalog *pkg.Collection) []*spdx.OtherLicense {
return result
}

// isSingularLicenseRef checks if the string is a singular LicenseRef-* identifier
func isSingularLicenseRef(s string) bool {
// Regular expression to match LicenseRef-* format (case-sensitive)
re := regexp.MustCompile(`^LicenseRef-[A-Za-z0-9_-]+$`)
var LicenseRefRegEx = regexp.MustCompile(`^LicenseRef-[A-Za-z0-9_-]+$`)
wagoodman marked this conversation as resolved.
Show resolved Hide resolved

// isSingularLicenseRef checks if the string is a singular LicenseRef-* identifier
func isLicenseRef(s string) bool {
// Match the input string against the regex
return re.MatchString(s)
return LicenseRefRegEx.MatchString(s)
}

// TODO: handle SPDX excludes file case
Expand Down
Loading