mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
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:
+50
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user