Skip to content

Commit 1c421a1

Browse files
authored
feat: base-serializer runs bomRefDiscrimination on vulnerabilities (#721)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 7fa0716 commit 1c421a1

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/serialize/baseSerializer.ts

+16-13
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,30 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
import type { Bom, BomRef, Component } from '../models'
20+
import { treeIteratorSymbol } from '../_helpers/tree'
21+
import type { Bom, BomRef } from '../models'
2122
import { BomRefDiscriminator } from './bomRefDiscriminator'
2223
import type { NormalizerOptions, Serializer, SerializerOptions } from './types'
2324

2425
export abstract class BaseSerializer<NormalizedBom> implements Serializer {
25-
#getAllBomRefs (bom: Bom): Iterable<BomRef> {
26-
const bomRefs = new Set<BomRef>()
27-
function iterComponents (cs: Iterable<Component>): void {
28-
for (const { bomRef, components } of cs) {
29-
bomRefs.add(bomRef)
30-
iterComponents(components)
26+
* #getAllBomRefs (bom: Bom): Generator<BomRef> {
27+
// region from components
28+
if (bom.metadata.component !== undefined) {
29+
yield bom.metadata.component.bomRef
30+
for (const { bomRef } of bom.metadata.component.components[treeIteratorSymbol]()) {
31+
yield bomRef
3132
}
3233
}
33-
34-
if (bom.metadata.component !== undefined) {
35-
bomRefs.add(bom.metadata.component.bomRef)
36-
iterComponents(bom.metadata.component.components)
34+
for (const { bomRef } of bom.components[treeIteratorSymbol]()) {
35+
yield bomRef
3736
}
38-
iterComponents(bom.components)
37+
// endregion from components
3938

40-
return bomRefs.values()
39+
// region from vulnerabilities
40+
for (const { bomRef } of bom.vulnerabilities) {
41+
yield bomRef
42+
}
43+
// endregion from vulnerabilities
4144
}
4245

4346
/**

0 commit comments

Comments
 (0)