Fix JS error on version parsing

This commit is contained in:
Andrei Pohilko
2022-11-27 09:48:28 +00:00
parent 34158a7a9c
commit 8de7941063
2 changed files with 15 additions and 8 deletions

View File

@@ -44,9 +44,16 @@ function buildChartCard(elm) {
<div class="col-1 rel-date text-nowrap"><span>today</span><div>Updated</div></div>
</div>`)
let chartName = elm.chart
// 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 chartName = elm.chart.substring(0, elm.chart.match(chartNameRegex).index - 1)
const match = elm.chart.match(chartNameRegex);
if (match) {
chartName = elm.chart.substring(0, match.index - 1)
} else {
// fall back to simple substr
chartName = elm.chart.substring(0, elm.chart.lastIndexOf("-"))
}
$.getJSON("/api/helm/repo/search?name=" + chartName).fail(function (xhr) {
// we're ok if we can't show icon and description
console.log("Failed to get repo name for charts", xhr)