@@ -416,6 +416,16 @@ func (m *Marshaler) normalizeLicenses(licenses []string) (string, []*spdx.OtherL
416
416
var otherLicenses = make (map [string ]* spdx.OtherLicense ) // licenseID -> OtherLicense
417
417
418
418
license := strings .Join (lo .Map (licenses , func (license string , index int ) string {
419
+ // We need to save text licenses before normalization,
420
+ // because it is impossible to handle all cases possible in the text.
421
+ // as an example, parse a license with 2 consecutive tokens (see https://github.com/aquasecurity/trivy/issues/8465)
422
+ if strings .HasPrefix (license , licensing .LicenseTextPrefix ) {
423
+ license = strings .TrimPrefix (license , licensing .LicenseTextPrefix )
424
+ otherLicense := m .newOtherLicense (license , true )
425
+ otherLicenses [otherLicense .LicenseIdentifier ] = otherLicense
426
+ return otherLicense .LicenseIdentifier
427
+ }
428
+
419
429
// e.g. GPL-3.0-with-autoconf-exception
420
430
license = strings .ReplaceAll (license , "-with-" , " WITH " )
421
431
license = strings .ReplaceAll (license , "-WITH-" , " WITH " )
@@ -424,13 +434,10 @@ func (m *Marshaler) normalizeLicenses(licenses []string) (string, []*spdx.OtherL
424
434
425
435
replaceOtherLicenses := func (expr expression.Expression ) expression.Expression {
426
436
var licenseName string
427
- var textLicense bool
428
437
switch e := expr .(type ) {
429
438
case expression.SimpleExpr :
430
- // Trim `text:--` prefix (expression.NormalizeForSPDX normalized `text://` prefix)
431
- if strings .HasPrefix (e .License , "text:--" ) {
432
- textLicense = true
433
- e .License = strings .TrimPrefix (e .License , "text:--" )
439
+ if strings .HasPrefix (e .License , LicenseRefPrefix ) {
440
+ return e
434
441
}
435
442
436
443
if expression .ValidateSPDXLicense (e .License ) || expression .ValidateSPDXException (e .License ) {
@@ -454,7 +461,7 @@ func (m *Marshaler) normalizeLicenses(licenses []string) (string, []*spdx.OtherL
454
461
licenseName = e .String ()
455
462
}
456
463
457
- l := m .newOtherLicense (licenseName , textLicense )
464
+ l := m .newOtherLicense (licenseName , false )
458
465
otherLicenses [l .LicenseIdentifier ] = l
459
466
return expression.SimpleExpr {License : l .LicenseIdentifier }
460
467
}
0 commit comments