Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ final class EvalEq extends AbstractEvalLhsRhs implements InterpretableCall {
public Val eval(org.projectnessie.cel.interpreter.Activation ctx) {
Val lVal = lhs.eval(ctx);
Val rVal = rhs.eval(ctx);
// Early return if any argument to the function is unknown or error.
if (isUnknownOrError(lVal)) {
return lVal;
}
if (isUnknownOrError(rVal)) {
return rVal;
}
return lVal.equal(rVal);
}

Expand Down Expand Up @@ -439,6 +446,13 @@ final class EvalNe extends AbstractEvalLhsRhs implements InterpretableCall {
public Val eval(org.projectnessie.cel.interpreter.Activation ctx) {
Val lVal = lhs.eval(ctx);
Val rVal = rhs.eval(ctx);
// Early return if any argument to the function is unknown or error.
if (isUnknownOrError(lVal)) {
return lVal;
}
if (isUnknownOrError(rVal)) {
return rVal;
}
Val eqVal = lVal.equal(rVal);
switch (eqVal.type().typeEnum()) {
case Err:
Expand Down
5 changes: 2 additions & 3 deletions core/src/test/java/org/projectnessie/cel/CELTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import static org.projectnessie.cel.ProgramOption.functions;
import static org.projectnessie.cel.ProgramOption.globals;
import static org.projectnessie.cel.Util.mapOf;
import static org.projectnessie.cel.common.types.BoolT.False;
import static org.projectnessie.cel.common.types.BoolT.True;
import static org.projectnessie.cel.common.types.Err.isError;
import static org.projectnessie.cel.common.types.Err.newErr;
Expand Down Expand Up @@ -657,10 +656,10 @@ void ResidualAst_Complex() {
assertThat(astIss.hasIssues()).isFalse();
Program prg = e.program(astIss.getAst(), evalOptions(OptTrackState, OptPartialEval));
EvalResult outDet = prg.eval(unkVars);
assertThat(outDet.getVal()).isSameAs(False);
assertThat(outDet.getVal()).isInstanceOf(UnknownT.class);
Ast residual = e.residualAst(astIss.getAst(), outDet.getEvalDetails());
String expr = astToString(residual);
assertThat(expr).isEqualTo("false");
assertThat(expr).isEqualTo("request.auth.claims.email == \"wiley@acme.co\"");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,32 @@ void missingIdentInSelect() {
assertThat(result).isInstanceOf(Err.class);
}

@Test
void equalityWithUnknownOperandStaysUnknown() {
assertThat(evalWithUnknownStringX("x == 'foo'")).isInstanceOf(UnknownT.class);
assertThat(evalWithUnknownStringX("x != 'foo'")).isInstanceOf(UnknownT.class);
assertThat(evalWithUnknownStringX("false || x == 'foo'")).isInstanceOf(UnknownT.class);

@dimas-b dimas-b Jun 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to add a test case for false && x == 'foo' -> false?.. or is it covered elsewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! One sec

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

assertThat(evalWithUnknownStringX("false && x == 'foo'")).isSameAs(False);
}

private static Val evalWithUnknownStringX(String expr) {
Source src = newTextSource(expr);
ParseResult parsed = Parser.parseAllMacros(src);
assertThat(parsed.hasErrors()).withFailMessage(parsed.getErrors()::toDisplayString).isFalse();

Container cont = testContainer("test");
TypeRegistry reg = newRegistry();
CheckerEnv env = newStandardCheckerEnv(cont, reg);
env.add(Decls.newVar("x", Decls.String));
CheckResult checkResult = Checker.Check(parsed, src, env);

AttributeFactory attrs = newPartialAttributeFactory(cont, reg, reg);
Interpreter interp = newStandardInterpreter(cont, reg, reg, attrs);
Interpretable i = interp.newInterpretable(checkResult.getCheckedExpr());
Activation vars = newPartialActivation(mapOf(), newAttributePattern("x"));
return i.eval(vars);
}

static class ConvTestCase {
final String in;
Val out;
Expand Down