Update to CEL 0.10.1 by pkwarren · Pull Request #327 · bufbuild/protovalidate-java · GitHub
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
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