From 8a0ce0216215f0355591be7730bcc698cbe4c77c Mon Sep 17 00:00:00 2001 From: Emily Rodriguez Date: Thu, 23 Mar 2023 17:33:38 -0500 Subject: [PATCH] add check that the text field exists before calling .match on it, also add logging. Logging does not display as expected Signed-off-by: Emily Rodriguez --- libs/hdf-converters/src/xccdf-results-mapper.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/hdf-converters/src/xccdf-results-mapper.ts b/libs/hdf-converters/src/xccdf-results-mapper.ts index 370b6710d0..4c0664888f 100644 --- a/libs/hdf-converters/src/xccdf-results-mapper.ts +++ b/libs/hdf-converters/src/xccdf-results-mapper.ts @@ -12,7 +12,7 @@ import { parseXml } from './base-converter'; import {CciNistMapping} from './mappings/CciNistMapping'; -import {DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS} from './utils/global'; +import {DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS, createWinstonLogger} from './utils/global'; const IMPACT_MAPPING: Map = new Map([ ['critical', 0.9], @@ -28,6 +28,8 @@ const RULE_RESULT_PATHS = ['cdf:rule-result', 'rule-result']; let idTracker = ''; let valueIdTracker: string | undefined = undefined; +let logger = createWinstonLogger('xccdf_results2hdf', 'INFO'); + function getRuleResultItem( testResult: Record, pathRuleResultPossibilities: string[], @@ -187,8 +189,12 @@ function extractCci(input: IIdent | IIdent[]): string[] { const output: string[] = []; inputArray.forEach((element) => { const text = _.get(element, 'text'); - if (text.match(CCI_REGEX)) { - output.push(text); + if(text) { + if (text.match(CCI_REGEX)) { + output.push(text); + } + } else { + logger.info(`No CCI text found for element: ${element}.`) } }); return output;