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
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ dependencies {
annotationProcessor(libs.nullaway)
api(libs.jspecify)
api(libs.protobuf.java)
implementation(libs.cel)
implementation(libs.cel) {
// https://github.com/google/cel-java/issues/748
exclude(group = "com.google.protobuf", module = "protobuf-javalite")
}

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

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
assertj = "3.27.3"
buf = "1.55.1"
cel = "0.9.1"
cel = "0.10.1"
error-prone = "2.40.0"
junit = "5.13.3"
maven-publish = "0.34.0"
Expand Down
26 changes: 1 addition & 25 deletions src/main/java/build/buf/protovalidate/CustomOverload.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.Descriptors;
import com.google.protobuf.Message;
import dev.cel.common.CelErrorCode;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.types.CelType;
import dev.cel.common.types.SimpleType;
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime.CelFunctionBinding;
import dev.cel.runtime.CelFunctionBinding;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -49,7 +47,6 @@ static List<CelFunctionBinding> create() {
ArrayList<CelFunctionBinding> bindings = new ArrayList<>();
bindings.addAll(
Arrays.asList(
celBytesToString(),
celGetField(),
celFormat(),
celStartsWithBytes(),
Expand All @@ -73,27 +70,6 @@ static List<CelFunctionBinding> create() {
return Collections.unmodifiableList(bindings);
}

/**
* This implements that standard {@code bytes_to_string} function. We override it because the CEL
* library doesn't validate that the bytes are valid utf-8.
*
* <p>Workaround until <a href="https://github.com/google/cel-java/pull/717">cel-java issue
* 717</a> lands.
*/
private static CelFunctionBinding celBytesToString() {
return CelFunctionBinding.from(
"bytes_to_string",
ByteString.class,
v -> {
if (!v.isValidUtf8()) {
throw new CelRuntimeException(
new IllegalArgumentException("invalid UTF-8 in bytes, cannot convert to string"),
CelErrorCode.BAD_FORMAT);
}
return v.toStringUtf8();
});
}

/**
* Creates a custom function overload for the "getField" operation.
*
Expand Down
16 changes: 1 addition & 15 deletions src/main/java/build/buf/protovalidate/ValidateLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import dev.cel.parser.CelStandardMacro;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeLibrary;
import dev.cel.runtime.CelStandardFunctions;
import dev.cel.runtime.CelStandardFunctions.StandardFunction;
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Conversions;

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

@Override
public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
runtimeBuilder
.addFunctionBindings(CustomOverload.create())
.setStandardEnvironmentEnabled(false)
.setStandardFunctions(
CelStandardFunctions.newBuilder()
.filterFunctions(
// CEL doesn't validate, that the bytes are valid utf-8, so we provide our own
// implementation.
(function, overload) ->
function != StandardFunction.STRING
|| !overload.equals(Conversions.BYTES_TO_STRING))
.build());
runtimeBuilder.addFunctionBindings(CustomOverload.create());
}
}