fix: Fixing the issue of the object.subset method failing to correctly compare array relationships (#5969)

Fixes:#5968

Signed-off-by: DCRUNNN <458891338@qq.com>
This commit is contained in:
DCRUNNN
2023-06-05 18:20:01 +08:00
committed by GitHub
parent a8080563a2
commit b97ee9daba
2 changed files with 52 additions and 2 deletions
+50
View File
@@ -384,5 +384,55 @@ cases:
note: subset/array and set 2
query: data.test.test_result = x
want_result:
- x: true
- data:
modules:
- |
package test
A := [1,2,3,4,5,6]
B := [4,5,6,8]
AsubB := object.subset(A, B)
BsubA := object.subset(B, A)
# Notice that there isn't really a well-defined way to "match" the two
# nested sets to one another, so we B is not a subset of A in this
# case.
test_result {
not AsubB # B is not a subset of A
not BsubA # A is not a subset of B
}
note: subset/arrays 5
query: data.test.test_result = x
want_result:
- x: true
- data:
modules:
- |
package test
A := [1,2,3,4,5,6]
B := [8,9,10]
AsubB := object.subset(A, B)
BsubA := object.subset(B, A)
# Notice that there isn't really a well-defined way to "match" the two
# nested sets to one another, so we B is not a subset of A in this
# case.
test_result {
not AsubB # B is not a subset of A
not BsubA # A is not a subset of B
}
note: subset/arrays 6
query: data.test.test_result = x
want_result:
- x: true
+2 -2
View File
@@ -193,12 +193,12 @@ func arraySubset(super, sub *ast.Array) bool {
return true
}
if superCursor == super.Len() {
if superCursor+subCursor == super.Len() {
return false
}
subElem := sub.Elem(subCursor)
superElem := sub.Elem(superCursor + subCursor)
superElem := super.Elem(superCursor + subCursor)
if superElem == nil {
return false
}