Skip to content
Open
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
3 changes: 3 additions & 0 deletions builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ var Builtins = []*Function{
if !n.CanInt() {
return nil, fmt.Errorf("cannot take %s elements", n.Kind())
}
if n.Int() < 0 {
return nil, fmt.Errorf("cannot take negative number of elements (got %d)", n.Int())
}
to := 0
if n.Int() > int64(v.Len()) {
to = v.Len()
Expand Down
1 change: 1 addition & 0 deletions builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func TestBuiltin_errors(t *testing.T) {
{`date("error")`, `invalid date`},
{`get()`, `invalid number of arguments (expected 2, got 0)`},
{`get(1, 2)`, `type int does not support indexing`},
{`take([1, 2, 3], -1)`, "cannot take negative number of elements (got -1)"},
{`bitnot("1")`, "cannot use string as argument (type int) to call bitnot (1:8)"},
{`bitand("1", 1)`, "cannot use string as argument (type int) to call bitand (1:8)"},
{`"10" | bitor(1)`, "cannot use string as argument (type int) to call bitor (1:1)"},
Expand Down
1 change: 1 addition & 0 deletions test/fuzz/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func FuzzExpr(f *testing.F) {
regexp.MustCompile(`invalid order .*, expected asc or desc`),
regexp.MustCompile(`unknown order, use asc or desc`),
regexp.MustCompile(`cannot use .* as a key for groupBy: type is not comparable`),
regexp.MustCompile(`cannot take negative number of elements`),
}

env := NewEnv()
Expand Down