Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Check member is defined before calling match (#616)
Browse files Browse the repository at this point in the history
* Check member is defined before calling match

Signed-off-by: Scott Rigby <[email protected]>

* Pass string not bang bang bool

Signed-off-by: Scott Rigby <[email protected]>
  • Loading branch information
scottrigby authored and prydonius committed Mar 15, 2019
1 parent 8370687 commit cb64e9f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions frontend/src/app/shared/services/charts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,25 @@ export class ChartsService {
let re = new RegExp(query, 'i');
return this.getCharts(repo).map(charts => {
return charts.filter(chart => {
return chart.attributes.name.match(re) ||
chart.attributes.description.match(re) ||
chart.attributes.repo.name.match(re) ||
return this.checkDefinedMatch(chart.attributes.name, re) ||
this.checkDefinedMatch(chart.attributes.description, re) ||
this.checkDefinedMatch(chart.attributes.repo.name, re) ||
this.arrayMatch(chart.attributes.keywords, re) ||
this.arrayMatch((chart.attributes.maintainers || []).map((m)=> { return m.name }), re) ||
this.arrayMatch(chart.attributes.sources, re)
})
})
}

checkDefinedMatch(member, matcher) {
return member && member.match(matcher);
}

arrayMatch(keywords: string[], re): boolean {
if(!keywords) return false

return keywords.some((keyword) => {
return !!keyword.match(re)
return this.checkDefinedMatch(keyword, re)
})
}

Expand Down Expand Up @@ -129,7 +133,7 @@ export class ChartsService {

/**
* Get the URL for retrieving the chart's icon
*
*
* @param {Chart} chart Chart object
*/
getChartIconURL(chart: Chart): string {
Expand Down

0 comments on commit cb64e9f

Please sign in to comment.