Skip to content

Commit f1ebca8

Browse files
authored
handle nil pointer carefully (#457)
1 parent c44ce48 commit f1ebca8

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

pkg/engine/score.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -324,34 +324,35 @@ func processFile(ctx context.Context, ep *Params, path string, fs billy.Filesyst
324324

325325
sr := scorer.NewScorer(ctx, doc)
326326

327-
if len(ep.Features) > 0 && len(ep.Categories) > 0 {
328-
fmt.Println("Using both features and categories, scoring will be done with mix of both")
329-
for _, cat := range ep.Categories {
330-
if len(cat) <= 0 {
331-
continue
332-
}
333-
for _, feat := range ep.Features {
334-
if len(feat) <= 0 {
327+
if len(ep.Categories) > 0 {
328+
if len(ep.Features) == 0 {
329+
for _, category := range ep.Categories {
330+
if len(category) <= 0 {
335331
continue
336332
}
337333
filter := scorer.Filter{
338-
Name: feat,
339-
Ftype: scorer.Mix,
340-
Category: cat,
334+
Name: category,
335+
Ftype: scorer.Category,
341336
}
342337
sr.AddFilter(filter)
343338
}
344-
}
345-
} else if len(ep.Categories) > 0 {
346-
for _, category := range ep.Categories {
347-
if len(category) <= 0 {
348-
continue
349-
}
350-
filter := scorer.Filter{
351-
Name: category,
352-
Ftype: scorer.Category,
339+
} else if len(ep.Features) > 0 {
340+
for _, cat := range ep.Categories {
341+
if len(cat) <= 0 {
342+
continue
343+
}
344+
for _, feat := range ep.Features {
345+
if len(feat) <= 0 {
346+
continue
347+
}
348+
filter := scorer.Filter{
349+
Name: feat,
350+
Ftype: scorer.Mix,
351+
Category: cat,
352+
}
353+
sr.AddFilter(filter)
354+
}
353355
}
354-
sr.AddFilter(filter)
355356
}
356357
} else if len(ep.Features) > 0 {
357358
for _, feature := range ep.Features {

0 commit comments

Comments
 (0)