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
17 changes: 17 additions & 0 deletions bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,23 @@ public void program_evaluateCanonicalTypesToNativeTypesDisabled_producesProtoVal
assertThat(result).containsExactly(com.google.protobuf.NullValue.NULL_VALUE, expectedNestedMap);
}

@Test
public void program_evaluateCanonicalTypesToNativeTypesDisabled_producesBytesProto()
throws Exception {
Cel cel =
standardCelBuilderWithMacros()
.addMessageTypes(TestAllTypes.getDescriptor())
.setContainer(CelContainer.ofName("cel.expr.conformance.proto3"))
.setOptions(CelOptions.current().evaluateCanonicalTypesToNativeValues(false).build())
.build();
CelAbstractSyntaxTree ast =
cel.compile("TestAllTypes{single_bytes: bytes('abc')}.single_bytes").getAst();

ByteString result = (ByteString) cel.createProgram(ast).eval();

assertThat(result).isEqualTo(ByteString.copyFromUtf8("abc"));
}

@Test
public void toBuilder_isImmutable() {
CelBuilder celBuilder = CelFactory.standardCelBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ public enum BytesOverload implements CelStandardOverload {
}
}),
STRING_TO_BYTES(
(celOptions, runtimeEquality) ->
CelFunctionBinding.from("string_to_bytes", String.class, CelByteString::copyFromUtf8)),
(celOptions, runtimeEquality) -> {
if (celOptions.evaluateCanonicalTypesToNativeValues()) {
return CelFunctionBinding.from(
"string_to_bytes", String.class, CelByteString::copyFromUtf8);
} else {
return CelFunctionBinding.from(
"string_to_bytes", String.class, ByteString::copyFromUtf8);
}
}),
;

private final FunctionBindingCreator bindingCreator;
Expand Down