Skip to content

Fix double dot range for invalid input #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2021
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
8 changes: 8 additions & 0 deletions expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@ func TestExpr(t *testing.T) {
`1 + 2 + Three`,
6,
},
{
`4 in 5..1`,
false,
},
{
`4..0`,
[]int{},
},
{
`MapArg({foo: "bar"})`,
"bar",
Expand Down
8 changes: 8 additions & 0 deletions optimizer/const_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ func (*constRange) Exit(node *Node) {
if min, ok := n.Left.(*IntegerNode); ok {
if max, ok := n.Right.(*IntegerNode); ok {
size := max.Value - min.Value + 1
// In case the max < min, patch empty slice
// as max must be greater than equal to min.
if size < 1 {
Patch(node, &ConstantNode{
Value: make([]int, 0),
})
return
}
// In this case array is too big. Skip generation,
// and wait for memory budget detection on runtime.
if size > 1e6 {
Expand Down
3 changes: 3 additions & 0 deletions vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ func exponent(a, b interface{}) float64 {

func makeRange(min, max int) []int {
size := max - min + 1
if size <= 0 {
return []int{}
}
rng := make([]int, size)
for i := range rng {
rng[i] = min + i
Expand Down