Skip to content
Open
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
1 change: 1 addition & 0 deletions PLANNER_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CelOptions options = CelOptions.current()
// .unwrapWellKnownTypesOnFunctionDispatch(...)
// .enableTimestampEpoch(...)
// .enableHeterogeneousNumericComparisons(...)
// .evaluateCanonicalTypesToNativeValues(...)
.build();

CelRuntime runtime = CelRuntimeFactory.plannerRuntimeBuilder()
Expand Down
16 changes: 16 additions & 0 deletions bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,22 @@ public void program_regexProgramSizeExceedsLimit_throws() throws Exception {
assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.INVALID_ARGUMENT);
}

@Test
@SuppressWarnings("deprecation") // Test only - verifying the deprecated option is rejected
public void planner_evaluateCanonicalTypesToNativeValuesDisabled_throws() {
CelRuntimeBuilder runtimeBuilder =
CelRuntimeFactory.plannerRuntimeBuilder()
.setOptions(CelOptions.current().evaluateCanonicalTypesToNativeValues(false).build());

IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, runtimeBuilder::build);

assertThat(e)
.hasMessageThat()
.isEqualTo(
"Misconfigured CelOptions: evaluateCanonicalTypesToNativeValues cannot be disabled.");
}

@Test
@SuppressWarnings("unchecked") // test only
public void program_evaluateCanonicalTypesToNativeTypesDisabled_producesProtoValues()
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/main/java/dev/cel/runtime/CelLiteRuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ private static void assertAllowedCelOptions(CelOptions celOptions) {
throw new IllegalArgumentException(
prefix + "unwrapWellKnownTypesOnFunctionDispatch cannot be disabled.");
}
if (!celOptions.evaluateCanonicalTypesToNativeValues()) {
throw new IllegalArgumentException(
prefix + "evaluateCanonicalTypesToNativeValues cannot be disabled.");
}
}

private static void addBindingToDispatcher(
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/main/java/dev/cel/runtime/CelRuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ private static void assertAllowedCelOptions(CelOptions celOptions) {
+ "enableTimestampEpoch cannot be disabled. Subset the environment instead using"
+ " setStandardFunctions method.");
}
if (!celOptions.evaluateCanonicalTypesToNativeValues()) {
throw new IllegalArgumentException(
prefix + "evaluateCanonicalTypesToNativeValues cannot be disabled.");
}
}

abstract CelRuntimeImpl autoBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,9 @@ public void eval_messageCreation_returnsMessageLite() throws Exception {
private enum CelOptionsTestCase {
UNSIGNED_LONG_DISABLED(newBaseTestOptions().enableUnsignedLongs(false).build()),
UNWRAP_WKT_DISABLED(newBaseTestOptions().unwrapWellKnownTypesOnFunctionDispatch(false).build()),
@SuppressWarnings("deprecation") // Test only - verifying the deprecated option is rejected
NATIVE_VALUES_DISABLED(
newBaseTestOptions().evaluateCanonicalTypesToNativeValues(false).build()),
;

private final CelOptions celOptions;
Expand Down
Loading