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
53 changes: 0 additions & 53 deletions bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1991,59 +1991,6 @@ public void program_nativeTypeUnknownsEnabled_asCallArguments() throws Exception
assertThat(result.attributes()).isEmpty();
}

@Test
@TestParameters("{expression: 'string(123)'}")
@TestParameters("{expression: 'string(123u)'}")
@TestParameters("{expression: 'string(1.5)'}")
@TestParameters("{expression: 'string(\"foo\")'}")
@TestParameters("{expression: 'string(b\"foo\")'}")
@TestParameters("{expression: 'string(timestamp(100))'}")
@TestParameters("{expression: 'string(duration(\"1h\"))'}")
public void program_stringConversionDisabled_throws(String expression) throws Exception {
Cel cel =
CelFactory.standardCelBuilder()
.setOptions(
CelOptions.current()
.enableTimestampEpoch(true)
.enableStringConversion(false)
.build())
.build();
CelAbstractSyntaxTree ast = cel.compile(expression).getAst();

CelEvaluationException e =
assertThrows(CelEvaluationException.class, () -> cel.createProgram(ast).eval());
assertThat(e).hasMessageThat().contains("No matching overload for function 'string'");
assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}

@Test
public void program_stringConcatenationDisabled_throws() throws Exception {
Cel cel =
CelFactory.standardCelBuilder()
.setOptions(CelOptions.current().enableStringConcatenation(false).build())
.build();
CelAbstractSyntaxTree ast = cel.compile("'foo' + 'bar'").getAst();

CelEvaluationException e =
assertThrows(CelEvaluationException.class, () -> cel.createProgram(ast).eval());
assertThat(e).hasMessageThat().contains("No matching overload for function '_+_'");
assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}

@Test
public void program_listConcatenationDisabled_throws() throws Exception {
Cel cel =
CelFactory.standardCelBuilder()
.setOptions(CelOptions.current().enableListConcatenation(false).build())
.build();
CelAbstractSyntaxTree ast = cel.compile("[1] + [2]").getAst();

CelEvaluationException e =
assertThrows(CelEvaluationException.class, () -> cel.createProgram(ast).eval());
assertThat(e).hasMessageThat().contains("No matching overload for function '_+_'");
assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}

@Test
public void program_comprehensionDisabled_throws() throws Exception {
Cel cel =
Expand Down
27 changes: 0 additions & 27 deletions common/src/main/java/dev/cel/common/CelOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ public enum ProtoUnsetFieldOptions {

public abstract ProtoUnsetFieldOptions fromProtoUnsetFieldOption();

public abstract boolean enableStringConversion();

public abstract boolean enableStringConcatenation();

public abstract boolean enableListConcatenation();

public abstract boolean enableComprehension();

public abstract int maxRegexProgramSize();
Expand Down Expand Up @@ -169,9 +163,6 @@ public static Builder newBuilder() {
.comprehensionMaxIterations(-1)
.unwrapWellKnownTypesOnFunctionDispatch(true)
.fromProtoUnsetFieldOption(ProtoUnsetFieldOptions.BIND_DEFAULT)
.enableStringConversion(true)
.enableStringConcatenation(true)
.enableListConcatenation(true)
.enableComprehension(true)
.maxRegexProgramSize(-1);
}
Expand Down Expand Up @@ -494,24 +485,6 @@ public abstract static class Builder {
*/
public abstract Builder fromProtoUnsetFieldOption(ProtoUnsetFieldOptions value);

/**
* Enables string() overloads for the runtime. This option exists to maintain parity with
* cel-cpp interpreter options.
*/
public abstract Builder enableStringConversion(boolean value);

/**
* Enables string concatenation overload for the runtime. This option exists to maintain parity
* with cel-cpp interpreter options.
*/
public abstract Builder enableStringConcatenation(boolean value);

/**
* Enables list concatenation overload for the runtime. This option exists to maintain parity
* with cel-cpp interpreter options.
*/
public abstract Builder enableListConcatenation(boolean value);

/**
* Enables comprehension (macros) for the runtime. Setting false has the same effect with
* assigning 0 for {@link #comprehensionMaxIterations()}. This option exists to maintain parity
Expand Down
14 changes: 0 additions & 14 deletions runtime/src/main/java/dev/cel/runtime/CelRuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,6 @@ private static void assertAllowedCelOptions(CelOptions celOptions) {

// Disallowed options in favor of subsetting
String subsettingError = "Subset the environment instead using setStandardFunctions method.";
if (!celOptions.enableStringConcatenation()) {
throw new IllegalArgumentException(
prefix + "enableStringConcatenation cannot be disabled. " + subsettingError);
}

if (!celOptions.enableStringConversion()) {
throw new IllegalArgumentException(
prefix + "enableStringConversion cannot be disabled. " + subsettingError);
}

if (!celOptions.enableListConcatenation()) {
throw new IllegalArgumentException(
prefix + "enableListConcatenation cannot be disabled. " + subsettingError);
}

if (!celOptions.enableTimestampEpoch()) {
throw new IllegalArgumentException(
Expand Down
11 changes: 0 additions & 11 deletions runtime/src/main/java/dev/cel/runtime/CelRuntimeLegacyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import dev.cel.common.types.CelTypes;
import dev.cel.common.values.CelValueProvider;
import dev.cel.common.values.ProtoMessageValueProvider;
import dev.cel.runtime.standard.AddOperator.AddOverload;
import dev.cel.runtime.standard.IntFunction.IntOverload;
import dev.cel.runtime.standard.TimestampFunction.TimestampOverload;
import java.util.Arrays;
Expand Down Expand Up @@ -381,16 +380,6 @@ private ImmutableSet<CelFunctionBinding> newStandardFunctionBindings(
return options.enableTimestampEpoch();
}
break;
case STRING:
return options.enableStringConversion();
case ADD:
if (standardOverload.equals(AddOverload.ADD_STRING)) {
return options.enableStringConcatenation();
}
if (standardOverload.equals(AddOverload.ADD_LIST)) {
return options.enableListConcatenation();
}
break;
default:
if (!options.enableHeterogeneousNumericComparisons()) {
return !CelStandardFunctions.isHeterogeneousComparison(
Expand Down
23 changes: 1 addition & 22 deletions runtime/src/main/java/dev/cel/runtime/LiteRuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,6 @@ private static void assertAllowedCelOptions(CelOptions celOptions) {
throw new IllegalArgumentException(
prefix + "unwrapWellKnownTypesOnFunctionDispatch cannot be disabled.");
}
if (!celOptions.enableStringConcatenation()) {
throw new IllegalArgumentException(
prefix
+ "enableStringConcatenation cannot be disabled. Subset the environment instead"
+ " using setStandardFunctions method.");
}
if (!celOptions.enableStringConversion()) {
throw new IllegalArgumentException(
prefix
+ "enableStringConversion cannot be disabled. Subset the environment instead using"
+ " setStandardFunctions method.");
}
if (!celOptions.enableListConcatenation()) {
throw new IllegalArgumentException(
prefix
+ "enableListConcatenation cannot be disabled. Subset the environment instead using"
+ " setStandardFunctions method.");
}
}

@Override
Expand Down Expand Up @@ -201,10 +183,7 @@ public CelLiteRuntime build() {
}

private Builder() {
this.celOptions =
CelOptions.current()
.enableCelValue(true)
.build();
this.celOptions = CelOptions.current().enableCelValue(true).build();
this.celValueProvider = (structType, fields) -> Optional.empty();
this.customFunctionBindings = new HashMap<>();
this.standardFunctionBuilder = ImmutableSet.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,6 @@ private enum CelOptionsTestCase {
CEL_VALUE_DISABLED(newBaseTestOptions().enableCelValue(false).build()),
UNSIGNED_LONG_DISABLED(newBaseTestOptions().enableUnsignedLongs(false).build()),
UNWRAP_WKT_DISABLED(newBaseTestOptions().unwrapWellKnownTypesOnFunctionDispatch(false).build()),
STRING_CONCAT_DISABLED(newBaseTestOptions().enableStringConcatenation(false).build()),
STRING_CONVERSION_DISABLED(newBaseTestOptions().enableStringConversion(false).build()),
LIST_CONCATENATION_DISABLED(newBaseTestOptions().enableListConcatenation(false).build()),
;

private final CelOptions celOptions;
Expand Down
Loading