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"));