fix(has): return false for negative array indices (#2769)

The sequence branch only checked the upper bound (len > index), so has(-1) returned true even on an empty array. Guard index >= 0.

Co-authored-by: max <max@example.com>
This commit is contained in:
maximilize
2026-08-03 13:15:14 +10:00
committed by GitHub
co-authored by max
parent 0d4490b875
commit 2fbc2eab20
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -71,6 +71,16 @@ var hasOperatorScenarios = []expressionScenario{
"D0, P[4], (!!bool)::true\n",
},
},
{
skipDoc: true,
description: "Negative array index is never present",
document: "[[1, 2, 3], []]",
expression: `.[] | has(-1)`,
expected: []string{
"D0, P[0], (!!bool)::false\n",
"D0, P[1], (!!bool)::false\n",
},
},
}
func TestHasOperatorScenarios(t *testing.T) {