mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Separate compiling and evaluation of dynamic categories.
This commit is contained in:
parent
ff31ebfa0f
commit
0745a0943d
3 changed files with 40 additions and 31 deletions
|
|
@ -453,22 +453,30 @@ func (w *worker) extractCategories(label string, advisory any) error {
|
|||
|
||||
const exprPrefix = "expr:"
|
||||
|
||||
var dynamic []string
|
||||
matcher := util.StringTreeMatcher(&dynamic)
|
||||
|
||||
for _, cat := range categories {
|
||||
if strings.HasPrefix(cat, exprPrefix) {
|
||||
expr := cat[len(exprPrefix):]
|
||||
var results []string
|
||||
matcher := util.StringTreeMatcher(&results)
|
||||
if err := w.expr.Extract(expr, matcher, true, advisory); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, result := range results {
|
||||
cats[result] = true
|
||||
// Compile first to check that the expression is okay.
|
||||
if _, err := w.expr.Compile(expr); err != nil {
|
||||
fmt.Printf("Compiling category expression %q failed: %v\n",
|
||||
expr, err)
|
||||
continue
|
||||
}
|
||||
// Ignore errors here as they result from not matching.
|
||||
w.expr.Extract(expr, matcher, true, advisory)
|
||||
} else { // Normal
|
||||
cats[cat] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Add dynamic categories.
|
||||
for _, cat := range dynamic {
|
||||
cats[cat] = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue