Skip to content

Commit

Permalink
Fix Array.Less slice out of bounds (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelocantos authored Jun 2, 2020
1 parent b102617 commit faca28b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rel/value_set_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (a Array) Less(v Value) bool {
return a.offset < b.offset
}
n := len(a.values)
if n < len(b.values) {
if n > len(b.values) {
n = len(b.values)
}
for i, av := range a.values[:n] {
Expand Down
5 changes: 5 additions & 0 deletions syntax/expr_set_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ func TestArrayWithHoles(t *testing.T) {
AssertCodesEvalToSameValue(t, `[10, 11, 12]`, `[10, , 12] with (@: 1, @item: 11)`)
AssertCodesEvalToSameValue(t, `[10, 11, 12]`, `[10, , 12, , , ] with (@: 1, @item: 11)`)
}

func TestSetOfArrays(t *testing.T) {
// This tests an error when stringifying sets of arrays.
AssertCodesEvalToSameValue(t, `'{[1], [1, 1]}'`, `$'${{[1, 1], [1]}}'`)
}

0 comments on commit faca28b

Please sign in to comment.