Skip to content

Commit 0c843b5

Browse files
authored
Update to CEL 0.10.1 (#327)
1 parent 8ec2916 commit 0c843b5

4 files changed

Lines changed: 7 additions & 42 deletions

File tree

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ dependencies {
338338
annotationProcessor(libs.nullaway)
339339
api(libs.jspecify)
340340
api(libs.protobuf.java)
341-
implementation(libs.cel)
341+
implementation(libs.cel) {
342+
// https://github.com/google/cel-java/issues/748
343+
exclude(group = "com.google.protobuf", module = "protobuf-javalite")
344+
}
342345

343346
buf("build.buf:buf:${libs.versions.buf.get()}:${osdetector.classifier}@exe")
344347

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
assertj = "3.27.3"
33
buf = "1.55.1"
4-
cel = "0.9.1"
4+
cel = "0.10.1"
55
error-prone = "2.40.0"
66
junit = "5.13.3"
77
maven-publish = "0.34.0"

src/main/java/build/buf/protovalidate/CustomOverload.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
import com.google.protobuf.ByteString;
1818
import com.google.protobuf.Descriptors;
1919
import com.google.protobuf.Message;
20-
import dev.cel.common.CelErrorCode;
21-
import dev.cel.common.CelRuntimeException;
2220
import dev.cel.common.types.CelType;
2321
import dev.cel.common.types.SimpleType;
2422
import dev.cel.runtime.CelEvaluationException;
25-
import dev.cel.runtime.CelRuntime.CelFunctionBinding;
23+
import dev.cel.runtime.CelFunctionBinding;
2624
import java.util.ArrayList;
2725
import java.util.Arrays;
2826
import java.util.Collections;
@@ -49,7 +47,6 @@ static List<CelFunctionBinding> create() {
4947
ArrayList<CelFunctionBinding> bindings = new ArrayList<>();
5048
bindings.addAll(
5149
Arrays.asList(
52-
celBytesToString(),
5350
celGetField(),
5451
celFormat(),
5552
celStartsWithBytes(),
@@ -73,27 +70,6 @@ static List<CelFunctionBinding> create() {
7370
return Collections.unmodifiableList(bindings);
7471
}
7572

76-
/**
77-
* This implements that standard {@code bytes_to_string} function. We override it because the CEL
78-
* library doesn't validate that the bytes are valid utf-8.
79-
*
80-
* <p>Workaround until <a href="https://github.com/google/cel-java/pull/717">cel-java issue
81-
* 717</a> lands.
82-
*/
83-
private static CelFunctionBinding celBytesToString() {
84-
return CelFunctionBinding.from(
85-
"bytes_to_string",
86-
ByteString.class,
87-
v -> {
88-
if (!v.isValidUtf8()) {
89-
throw new CelRuntimeException(
90-
new IllegalArgumentException("invalid UTF-8 in bytes, cannot convert to string"),
91-
CelErrorCode.BAD_FORMAT);
92-
}
93-
return v.toStringUtf8();
94-
});
95-
}
96-
9773
/**
9874
* Creates a custom function overload for the "getField" operation.
9975
*

src/main/java/build/buf/protovalidate/ValidateLibrary.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
import dev.cel.parser.CelStandardMacro;
2323
import dev.cel.runtime.CelRuntimeBuilder;
2424
import dev.cel.runtime.CelRuntimeLibrary;
25-
import dev.cel.runtime.CelStandardFunctions;
26-
import dev.cel.runtime.CelStandardFunctions.StandardFunction;
27-
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Conversions;
2825

2926
/**
3027
* Custom {@link CelCompilerLibrary} and {@link CelRuntimeLibrary}. Provides all the custom
@@ -57,17 +54,6 @@ public void setCheckerOptions(CelCheckerBuilder checkerBuilder) {
5754

5855
@Override
5956
public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
60-
runtimeBuilder
61-
.addFunctionBindings(CustomOverload.create())
62-
.setStandardEnvironmentEnabled(false)
63-
.setStandardFunctions(
64-
CelStandardFunctions.newBuilder()
65-
.filterFunctions(
66-
// CEL doesn't validate, that the bytes are valid utf-8, so we provide our own
67-
// implementation.
68-
(function, overload) ->
69-
function != StandardFunction.STRING
70-
|| !overload.equals(Conversions.BYTES_TO_STRING))
71-
.build());
57+
runtimeBuilder.addFunctionBindings(CustomOverload.create());
7258
}
7359
}

0 commit comments

Comments
 (0)