Skip to content

Commit

Permalink
Handle errors in regex match
Browse files Browse the repository at this point in the history
  • Loading branch information
ronahk committed Jan 15, 2023
1 parent f3c66ec commit 87ee388
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/dashboard/static/list-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ function buildChartCard(elm) {
</div>`)

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 {
Expand Down

0 comments on commit 87ee388

Please sign in to comment.