Skip to content

Commit

Permalink
🐛 prevent crashes on calling dict.containsOnly without array (#1233)
Browse files Browse the repository at this point in the history
This technically doesnt work and is in line with the way it works for
arrays. However, I think we should change this because more users are
runingn into this...

---------

Signed-off-by: Dominik Richter <[email protected]>
Co-authored-by: Preslav <[email protected]>
  • Loading branch information
arlimus and preslavgerchev authored May 23, 2023
1 parent 63f262b commit 55adc59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llx/builtin_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,10 @@ func dictDifferenceV2(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64)
return &RawData{Type: bind.Type, Error: errors.New("cannot compute difference of lists, argument is not a list")}, 0, nil
}

filters := arg.Value.([]interface{})
filters, ok := arg.Value.([]interface{})
if !ok {
return &RawData{Type: bind.Type, Error: errors.New("tried to call function with a non-array, please make sure the argument is an array")}, 0, nil
}

var res []interface{}
var skip bool
Expand Down
12 changes: 12 additions & 0 deletions resources/packs/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,18 @@ func TestDict_Methods_Contains(t *testing.T) {
p + "params['string-array'].contains('a')",
1, true,
},
{
p + "params['string-array'].containsOnly(['c', 'a', 'b'])",
1, true,
},
{
p + "params['string-array'].containsOnly(['a', 'b'])",
1, false,
},
// {
// p + "params['string-array'].containsOnly('a')",
// 1, false,
// },
{
p + "params['string-array'].none('a')",
1, false,
Expand Down

0 comments on commit 55adc59

Please sign in to comment.