fix(sbom): keep the dash of LicenseRef- for a name without usable characters; purl keys are decoded
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 9m7s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-15 13:53:44 +02:00
1 parent 887bd62986
commit e93219dc86
1 file changed
+9 -2
+9 -2
View File
@@ -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"));