Skip to content

Commit

Permalink
Hotfix for metadata potentially being undefined in the SBOM json (#1132)
Browse files Browse the repository at this point in the history
## Description

Adds an undefined check for metadata to viewer.js


![image](https://user-images.githubusercontent.com/3977569/207736087-105fbfd6-85db-4b8f-a58c-9abcebf38a16.png)

## Related Issue

Fixes #1131

## Type of change

- [X] Bug fix (non-breaking change which fixes an issue)
  • Loading branch information
Racer159 authored Dec 14, 2022
1 parent 55b23b3 commit c028831
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/internal/packager/sbom/viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function initData() {
artifact.name,
artifact.version,
fileList(artifact.metadata),
artifact.metadata.description || '-',
(artifact.metadata.maintainer || '-').replace(/\u003c(.*)\u003e/, '&nbsp;|&nbsp;&nbsp;<a href="mailto:$1">$1</a>'),
artifact.metadata.installedSize || '-',
(artifact.metadata && artifact.metadata.description) || '-',
((artifact.metadata && artifact.metadata.maintainer) || '-').replace(/\u003c(.*)\u003e/, '&nbsp;|&nbsp;&nbsp;<a href="mailto:$1">$1</a>'),
(artifact.metadata && artifact.metadata.installedSize) || '-',
];
});

Expand Down Expand Up @@ -61,15 +61,17 @@ function initData() {
}

function fileList(metadata) {
const list = (metadata.files || [])
.map(file => {
return file.path || ''
})
.filter(test => test)

if (list.length > 0) {
flatList = list.sort().join('<br>');
return `<a href="#" onClick="showModal('${metadata.package}','${flatList}')">${list.length} files</a>`
if (metadata) {
const list = (metadata.files || [])
.map(file => {
return file.path || ''
})
.filter(test => test)

if (list.length > 0) {
flatList = list.sort().join('<br>');
return `<a href="#" onClick="showModal('${metadata.package}','${flatList}')">${list.length} files</a>`
}
}

return '-';
Expand Down

0 comments on commit c028831

Please sign in to comment.