From e93219dc86aacefe85a8103c98082caef3757169 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:53:44 +0200 Subject: [PATCH] fix(sbom): keep the dash of LicenseRef- for a name without usable characters; purl keys are decoded Co-Authored-By: Claude Opus 5.5 --- compliance-core/src/models/license.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compliance-core/src/models/license.rs b/compliance-core/src/models/license.rs index 9bf4bad..4925ad2 100644 --- a/compliance-core/src/models/license.rs +++ b/compliance-core/src/models/license.rs @@ -274,7 +274,8 @@ pub fn license_ref(name: &str) -> String { dash = true; } } - while id.ends_with('-') { + // Only a dash after the name, never the one of `LicenseRef-`. + while id.len() > "LicenseRef-".len() && id.ends_with('-') { id.pop(); } if id.len() == "LicenseRef-".len() { @@ -385,7 +386,12 @@ mod tests { fn a_package_is_keyed_without_its_version() { assert_eq!( package_key("core", "npm", Some("pkg:npm/%40angular/core@17.0.1?x=y")), - "pkg:npm/%40angular/core" + "pkg:npm/@angular/core" + ); + // Encoded or not, the scope is the same package. + assert_eq!( + package_key("core", "npm", Some("pkg:npm/@angular/core@16.2.0")), + "pkg:npm/@angular/core" ); assert_eq!(package_key("Foo", "nuget", None), "nuget:Foo"); assert_eq!(package_key("Foo", "nuget", Some("not a purl")), "nuget:Foo"); @@ -425,6 +431,7 @@ mod tests { ); assert_eq!(license_ref(" ©© "), "LicenseRef-custom"); assert_eq!(license_ref("v1.2 / 2020"), "LicenseRef-v1.2-2020"); + assert_eq!(license_ref("EULA!"), "LicenseRef-EULA"); assert!(is_license_ref("LicenseRef-a.b-1")); assert!(!is_license_ref("LicenseRef-")); assert!(!is_license_ref("LicenseRef-a b"));