Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder msg, WellKnownProto wel
"Unpacking failed for message: " + message.getDescriptorForType().getFullName(), e);
}
return toRuntimeValue(unpackedMessage);
case FIELD_MASK:
// The base-class default converts FieldMask to a comma-separated string (its JSON wire
// form). That's correct when a FieldMask is being assigned to a google.protobuf.Value
// field (see ProtoLiteAdapter/CelProtoJsonAdapter, which handle JSON assignment at
// their own level), but it breaks CEL expressions that access fields on the FieldMask
// itself (e.g. `fieldMask.paths`) — the string has no field `paths`.
//
// The CEL spec's WKT conversion table does not list FieldMask. cel-go treats it as a
// regular message, as does cel-java's legacy ProtoLiteAdapter.adaptValueToWellKnownProto
// for non-JSON contexts. Preserve that behavior here by wrapping as a ProtoMessageValue.
return ProtoMessageValue.create(
(Message) message, celDescriptorPool, this, celOptions.enableJsonFieldNames());
default:
return super.fromWellKnownProto(message, wellKnownProto);
}
Expand Down Expand Up @@ -154,11 +166,13 @@ public Object fromProtoMessageFieldToCelValue(Message message, FieldDescriptor f

return toRuntimeValue(result);
case UINT32:
case FIXED32:
if (!fieldDescriptor.isRepeated()) {
return UnsignedLong.valueOf((int) result);
}
break;
case UINT64:
case FIXED64:
if (!fieldDescriptor.isRepeated()) {
return UnsignedLong.fromLongBits((long) result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,59 @@ public void selectField_durationOutOfRange_success(int seconds, int nanos) {
.isEqualTo(Duration.ofSeconds(seconds, nanos));
}

// The CEL spec maps proto's fixed32/fixed64 to CEL's uint. cel-java's checker (via
// DescriptorMappings) and its legacy DescriptorMessageProvider (via ProtoAdapter) both honor
// this. The CelValue path via ProtoCelValueConverter.fromProtoMessageFieldToCelValue used to
// miss FIXED32/FIXED64, falling through to normalizePrimitive and producing Integer/Long. That
// caused overload resolution to fail at runtime with "No matching overload" when the checker
// said uint but the runtime served a signed integer.
@Test
public void selectField_fixed32_returnsUnsignedLong() {
TestAllTypes testAllTypes = TestAllTypes.newBuilder().setSingleFixed32(1).build();

ProtoMessageValue protoMessageValue =
ProtoMessageValue.create(
testAllTypes, DefaultDescriptorPool.INSTANCE, PROTO_CEL_VALUE_CONVERTER, false);

assertThat(protoMessageValue.select("single_fixed32")).isEqualTo(UnsignedLong.valueOf(1L));
}

@Test
public void selectField_fixed64_returnsUnsignedLong() {
TestAllTypes testAllTypes =
TestAllTypes.newBuilder().setSingleFixed64(UnsignedLong.MAX_VALUE.longValue()).build();

ProtoMessageValue protoMessageValue =
ProtoMessageValue.create(
testAllTypes, DefaultDescriptorPool.INSTANCE, PROTO_CEL_VALUE_CONVERTER, false);

assertThat(protoMessageValue.select("single_fixed64")).isEqualTo(UnsignedLong.MAX_VALUE);
}

// FieldMask is not in the CEL spec's WKT conversion table and should be treated as a regular
// message so expressions like `fieldMask.paths` work. The base-class default
// (BaseProtoCelValueConverter) converts FieldMask to a comma-separated string in
// fromWellKnownProto; that's only correct in JSON-assignment contexts (handled separately by
// CelProtoJsonAdapter). ProtoCelValueConverter overrides to preserve FieldMask as a
// ProtoMessageValue so field selection continues to work.
@Test
public void selectField_fieldMask_returnsProtoMessageValue() {
TestAllTypes testAllTypes =
TestAllTypes.newBuilder()
.setFieldMask(
com.google.protobuf.FieldMask.newBuilder().addPaths("foo").addPaths("bar"))
.build();

ProtoMessageValue protoMessageValue =
ProtoMessageValue.create(
testAllTypes, DefaultDescriptorPool.INSTANCE, PROTO_CEL_VALUE_CONVERTER, false);

Object selected = protoMessageValue.select("field_mask");
assertThat(selected).isInstanceOf(ProtoMessageValue.class);
assertThat(((ProtoMessageValue) selected).select("paths"))
.isEqualTo(ImmutableList.of("foo", "bar"));
}

@SuppressWarnings("ImmutableEnumChecker") // Test only
private enum SelectFieldJsonValueTestCase {
NULL(Value.newBuilder().build(), NullValue.NULL_VALUE),
Expand Down
2 changes: 1 addition & 1 deletion publish/cel_version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Maven artifact version for CEL."""
CEL_VERSION = "0.13.0"
CEL_VERSION = "0.13.0-planner-SNAPSHOT"