Skip to content

Commit debd35b

Browse files
authored
fix: bug with NOT clause reduction when condition is an array (#848)
1 parent d60602f commit debd35b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/runtime/src/enhancements/policy/policy-utils.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,19 @@ export class PolicyUtil {
189189
}
190190

191191
case 'NOT': {
192-
const r = this.reduce(value);
193-
if (this.isFalse(r)) {
194-
// NOT false => true, thus eliminated (not adding into result)
195-
} else if (this.isTrue(r)) {
196-
// NOT true => false, eliminate all other keys and set entire condition to false
192+
const children = enumerate(value)
193+
.map((c: any) => this.reduce(c))
194+
.filter((c) => c !== undefined && !this.isFalse(c));
195+
if (children.length === 0) {
196+
// all clauses are false, result is a constant true,
197+
// thus eliminated (not adding into result)
198+
} else if (children.some((c) => this.isTrue(c))) {
199+
// some clauses are true, result is a constant false,
200+
// eliminate all other keys and set entire condition to false
197201
Object.keys(result).forEach((k) => delete result[k]);
198202
result['OR'] = []; // this will cause the outer loop to exit too
199203
} else {
200-
result[key] = r;
204+
result[key] = !Array.isArray(value) && children.length === 1 ? children[0] : children;
201205
}
202206
break;
203207
}

0 commit comments

Comments
 (0)