From 87ee388bfb5258c33dd479ee8a05145c86dd9761 Mon Sep 17 00:00:00 2001 From: ronahk Date: Sun, 15 Jan 2023 12:18:40 +0200 Subject: [PATCH] Handle errors in regex match --- pkg/dashboard/static/list-view.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/dashboard/static/list-view.js b/pkg/dashboard/static/list-view.js index ca2ee23e..b8530a2a 100644 --- a/pkg/dashboard/static/list-view.js +++ b/pkg/dashboard/static/list-view.js @@ -45,9 +45,15 @@ function buildChartCard(elm) { `) let chartName = elm.chart + let match = null // semver2 regex , add optional v prefix const chartNameRegex = 'v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?' - const match = elm.chart.match(chartNameRegex); + if (!new RegExp(chartNameRegex).test(chartName)) { + alert('Chart name does not match chart name regex.') + } else { + match = chartName.match(chartNameRegex); + } + if (match) { chartName = elm.chart.substring(0, match.index - 1) } else {