From 55adc598c86ed45e41badd2c62e5d6d003d0af8a Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Tue, 23 May 2023 02:35:49 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20prevent=20crashes=20on=20calling?= =?UTF-8?q?=20dict.containsOnly=20without=20array=20(#1233)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Preslav --- llx/builtin_map.go | 5 ++++- resources/packs/core/core_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/llx/builtin_map.go b/llx/builtin_map.go index 6db4fe1161..3184232a54 100644 --- a/llx/builtin_map.go +++ b/llx/builtin_map.go @@ -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 diff --git a/resources/packs/core/core_test.go b/resources/packs/core/core_test.go index 124f3529ef..b2bd59608c 100644 --- a/resources/packs/core/core_test.go +++ b/resources/packs/core/core_test.go @@ -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,