Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions expr/builtins/builtins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ var builtinTests = []testBuiltins{
{`filter(split("apples,oranges",","),"ora%")`, value.NewStringsValue([]string{"apples"})},
{`filter(split("apples,oranges",","),["ora%","ban*"])`, value.NewStringsValue([]string{"apples"})},
{`filter(split("apples,oranges",","), ["ora*","notmatch","stuff"] )`, value.NewStringsValue([]string{"apples"})},
{`filter(split("apples,oranges,",","), [""] )`, value.NewStringsValue([]string{"apples", "oranges"})},
{`filter("apples","")`, value.NewStringValue("apples")},
{`filter("apples","ban*")`, value.NewStringValue("apples")},
{`filter("apples","ban")`, value.NewStringValue("apples")},
{`filter("apples","app*")`, value.NilValueVal},
Expand Down
15 changes: 15 additions & 0 deletions expr/builtins/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func FilterEval(ctx expr.EvalContext, vals []value.Value) (value.Value, bool) {
filteredOut = true
break
}
} else if filter == "" {
if rowKey == "" && v != nil {
filteredOut = true
break
}
} else {
if strings.HasPrefix(rowKey, filter) && v != nil {
filteredOut = true
Expand All @@ -132,6 +137,11 @@ func FilterEval(ctx expr.EvalContext, vals []value.Value) (value.Value, bool) {
anyMatches = true
break
}
} else if filter == "" {
if val.Val() == "" {
anyMatches = true
break
}
} else {
if strings.HasPrefix(val.Val(), filter) {
anyMatches = true
Expand All @@ -157,6 +167,11 @@ func FilterEval(ctx expr.EvalContext, vals []value.Value) (value.Value, bool) {
filteredOut = true
break
}
} else if filter == "" {
if sv == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nit but we should filter out nil values too

filteredOut = true
break
}
} else {
if strings.HasPrefix(sv, filter) && sv != "" {
filteredOut = true
Expand Down