From 34440aeddd08ee7ca02d78d7ba26cd57579fbdd2 Mon Sep 17 00:00:00 2001 From: frankgrimes97 Date: Thu, 29 Aug 2024 17:08:26 -0400 Subject: [PATCH] Fix Invalid Array Length error when severity_threshold exceeded --- src/main.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index da9856f..d20871c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -116,9 +116,11 @@ async function run(): Promise { } } if (vulnidColorized.length > 0 && vulnsevColorized.length > 0) { - const pkgTxt = `${chalk.magenta(v.PkgName)}${new Array(40 - chalk.magenta(v.PkgName).length).join(' ')}`; - const vulnidTxt = `${vulnidColorized}${new Array(40 - vulnidColorized.length).join(' ')}`; - const vulnsevTxt = `${vulnsevColorized}${new Array(30 - vulnsevColorized.length).join(' ')}`; + const pkgTextPadding = Math.max(40 - v.PkgName.length, 0); + const pkgTxt = `${chalk.magenta(v.PkgName)}${new Array(pkgTextPadding).join(' ')}`; + const vulnidTxtPadding = Math.max(40 - v.VulnerabilityID.length, 0); + const vulnidTxt = `${vulnidColorized}${new Array(vulnidTxtPadding).join(' ')}`; + const vulnsevTxtPadding = Math.max(30 - v.Severity.length, 0); res.unhealthyMsg = `${pkgTxt} ${vulnidTxt} ${vulnsevTxt} ${v.Title}`; isUnhealthy = true; }