Skip to content

Commit 574b19b

Browse files
committed
fix: [error] cve.References is not iterable
1 parent 53bf0ed commit 574b19b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

__tests__/utils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { isIterable } from '../src/utils';
2+
3+
describe('isIterable', () => {
4+
test.each([
5+
['test', true],
6+
[[], true],
7+
[['this', 'is', 'test'], true],
8+
[{ id: 'test' }, false],
9+
])('input %s', (obj, expected) => {
10+
expect(isIterable(obj)).toBe(expected);
11+
});
12+
});

src/trivy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import fetch, { Response } from 'node-fetch';
66
import { spawnSync, SpawnSyncReturns } from 'child_process';
77

88
import { TrivyOption, Vulnerability } from './interface';
9+
import { isIterable } from './utils';
910

1011
export class Downloader {
1112
githubClient: Octokit;
@@ -180,7 +181,9 @@ export class Trivy {
180181
vulnTable += `|${cve.InstalledVersion || 'N/A'}|${cve.FixedVersion ||
181182
'N/A'}|`;
182183

183-
for (const reference of cve.References) {
184+
const references = cve.References;
185+
if (!isIterable(references)) continue;
186+
for (const reference of references) {
184187
vulnTable += `${reference || 'N/A'}<br>`;
185188
}
186189

src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function isIterable(obj: Object): Boolean {
2+
return obj != null && typeof obj[Symbol.iterator] === 'function';
3+
}

0 commit comments

Comments
 (0)