From 6cc01caa4bf95b027e56204c7c8207b368fdbf03 Mon Sep 17 00:00:00 2001 From: cd-rite <61710958+cd-rite@users.noreply.github.com> Date: Tue, 20 Dec 2022 09:29:27 -0500 Subject: [PATCH] fix: set revision string optionally (#38) --- lib/ReviewParser.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ReviewParser.js b/lib/ReviewParser.js index a175f85..5677720 100644 --- a/lib/ReviewParser.js +++ b/lib/ReviewParser.js @@ -123,13 +123,14 @@ iStigElement.forEach(iStig => { let checklist = {} // get benchmarkId - let stigIdElement = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'stigid' )[0] + let stigIdElement = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'stigid' )?.[0] checklist.benchmarkId = stigIdElement.SID_DATA.replace('xccdf_mil.disa.stig_benchmark_', '') - // get revision - const stigVersion = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'version' )[0].SID_DATA - let stigReleaseInfo = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'releaseinfo' )[0].SID_DATA - const stigRelease = stigReleaseInfo.match(/Release:\s*(.+?)\s/)[1] - const stigRevisionStr = `V${stigVersion}R${stigRelease}` + // get revision data. Extract digits from version and release fields to create revisionStr, if possible. + const stigVersionData = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'version' )?.[0].SID_DATA + let stigVersion = stigVersionData.match(/(\d+)/)?.[1] + let stigReleaseInfo = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'releaseinfo' )?.[0].SID_DATA + const stigRelease = stigReleaseInfo.match(/Release:\s*(.+?)\s/)?.[1] + const stigRevisionStr = stigVersion && stigRelease ? `V${stigVersion}R${stigRelease}` : null checklist.revisionStr = stigRevisionStr if (checklist.benchmarkId) { @@ -399,7 +400,7 @@ const parser = new XMLParser(parseOptions) let parsed = parser.parse(data) - // Baic sanity checks + // Basic sanity checks if (!parsed.Benchmark) throw (new Error("No Benchmark element")) if (!parsed.Benchmark.TestResult) throw (new Error("No TestResult element")) if (!parsed.Benchmark.TestResult['target']) throw (new Error("No target element"))