diff --git a/build.gradle.kts b/build.gradle.kts index b41f92e2..59ad90a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ffb2ab2a..9aa47f5e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" diff --git a/src/main/java/build/buf/protovalidate/CustomOverload.java b/src/main/java/build/buf/protovalidate/CustomOverload.java index bc377a52..3494d00d 100644 --- a/src/main/java/build/buf/protovalidate/CustomOverload.java +++ b/src/main/java/build/buf/protovalidate/CustomOverload.java @@ -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; @@ -49,7 +47,6 @@ static List create() { ArrayList bindings = new ArrayList<>(); bindings.addAll( Arrays.asList( - celBytesToString(), celGetField(), celFormat(), celStartsWithBytes(), @@ -73,27 +70,6 @@ static List 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. - * - *

Workaround until cel-java issue - * 717 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. * diff --git a/src/main/java/build/buf/protovalidate/ValidateLibrary.java b/src/main/java/build/buf/protovalidate/ValidateLibrary.java index f82c744b..73404023 100644 --- a/src/main/java/build/buf/protovalidate/ValidateLibrary.java +++ b/src/main/java/build/buf/protovalidate/ValidateLibrary.java @@ -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 @@ -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()); } }