Skip to content

Commit e44b210

Browse files
committed
fix(fossid-webapp): Return empty PURL when artifact name is empty
The packageurl-jvm library throws MalformedPackageURLException when the name component is empty. This can happen for snippets with empty artifact names. Return an empty string early when the name is blank. This is a fixup for 334810d. Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
1 parent 6159101 commit e44b210

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,21 @@ private fun Set<Snippet>.mapSnippetFindingsForFile(
313313
}
314314

315315
val snippetProvenance = ArtifactProvenance(RemoteArtifact(url, Hash.NONE))
316-
val purl = snippet.purl ?: PackageURLBuilder.aPackageURL()
317-
.withType(urlToPackageType(url))
318-
.withNamespace(snippet.author)
319-
.withName(snippet.artifact)
320-
.withVersion(snippet.version)
321-
.build()
322-
.canonicalize()
316+
val purl = when {
317+
snippet.purl != null -> snippet.purl
318+
319+
snippet.artifact.isNullOrEmpty() -> ""
320+
321+
else -> {
322+
PackageURLBuilder.aPackageURL()
323+
.withType(urlToPackageType(url))
324+
.withNamespace(snippet.author)
325+
.withName(snippet.artifact)
326+
.withVersion(snippet.version)
327+
.build()
328+
.canonicalize()
329+
}
330+
}
323331

324332
val additionalSnippetData = mutableMapOf(
325333
FossId.SNIPPET_DATA_ID to snippet.id.toString(),

0 commit comments

Comments
 (0)