From 7bb08d1a93a96e4752f84e60c5fa21a6e66c0d62 Mon Sep 17 00:00:00 2001 From: Matt Rutkowski Date: Thu, 13 Jun 2024 17:05:05 -0500 Subject: [PATCH] extract only the actual SPDX ID from scanline it was found at Signed-off-by: Matt Rutkowski --- identifier/identifier.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/identifier/identifier.go b/identifier/identifier.go index ebeba6a..6bd30b1 100644 --- a/identifier/identifier.go +++ b/identifier/identifier.go @@ -181,7 +181,8 @@ func IdentifyLicensesInFile(filePath string, options Options, licenseLibrary *li const SPDX_ID_KEY = "SPDX-License-Identifier:" var LEN_SPDX_ID_KEY = len(SPDX_ID_KEY) -var SPDX_ID_KEY_BYTES = []byte(SPDX_ID_KEY) + +//var SPDX_ID_KEY_BYTES = []byte(SPDX_ID_KEY) func findSPDXIdentifierInFile(filePath string, maxLines int) (licenseMatches []licenseMatch, err error) { var file *os.File @@ -208,9 +209,14 @@ func findSPDXIdentifierInFile(filePath string, maxLines int) (licenseMatches []l } if foundLine != "" { idx := strings.Index(foundLine, SPDX_ID_KEY) + // find start index of where the actual SPDX ID is by + // adding in the length of the SPDX License Identifier key + // Then trim any whitespace to extract the actual SPDX ID value + idx += LEN_SPDX_ID_KEY spdxIdPlus := foundLine[idx:] + //fmt.Printf("line (%v): `%s`; id: `%s`\n", idx, foundLine, spdxIdPlus) var match licenseMatch - match.LicenseId = spdxIdPlus + match.LicenseId = strings.TrimSpace(spdxIdPlus) licenseMatches = append(licenseMatches, match) } return