Skip to content

Commit 78dfcb5

Browse files
l46kokcopybara-github
authored andcommitted
Enable UnsignedLongs by default in CelOptions
PiperOrigin-RevId: 665962755
1 parent c3c493a commit 78dfcb5

6 files changed

Lines changed: 13 additions & 8 deletions

File tree

common/src/main/java/dev/cel/common/CelOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public static Builder current() {
211211
return newBuilder()
212212
.enableReservedIds(true)
213213
.enableUnsignedComparisonAndArithmeticIsUnsigned(true)
214+
.enableUnsignedLongs(true)
214215
.enableRegexPartialMatch(true)
215216
.errorOnDuplicateMapKeys(true)
216217
.errorOnIntWrap(true)

common/src/main/java/dev/cel/common/ExprFeatures.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public enum ExprFeatures {
159159
UNSIGNED_COMPARISON_AND_ARITHMETIC_IS_UNSIGNED,
160160
ENABLE_NAMESPACED_DECLARATIONS,
161161
ERROR_ON_WRAP,
162-
ERROR_ON_DUPLICATE_KEYS);
162+
ERROR_ON_DUPLICATE_KEYS,
163+
ENABLE_UNSIGNED_LONGS);
163164

164165
public static final ImmutableSet<ExprFeatures> LEGACY = ImmutableSet.of(LEGACY_JAVA_EQUALITY);
165166
}

common/src/test/java/dev/cel/common/internal/ProtoAdapterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static List<Object[]> data() {
106106
},
107107
{1L, Int64Value.of(1L), LEGACY},
108108
{1L, Any.pack(Int64Value.of(1L)), LEGACY},
109-
{1L, UInt64Value.of(1L), LEGACY},
109+
{UnsignedLong.valueOf(1L), UInt64Value.of(1L), LEGACY},
110110
{"hello", StringValue.of("hello"), LEGACY},
111111
{"hello", Any.pack(StringValue.of("hello")), LEGACY},
112112
{"hello", Value.newBuilder().setStringValue("hello").build(), LEGACY},

common/src/test/java/dev/cel/common/values/ProtoMessageValueProviderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ public void newValue_createProtoMessage_fieldsPopulated() {
106106
assertThat(protoMessageValue.select(StringValue.create("single_int64")))
107107
.isEqualTo(IntValue.create(2L));
108108
assertThat(protoMessageValue.select(StringValue.create("single_uint32")))
109-
.isEqualTo(UintValue.create(3L, false));
109+
.isEqualTo(UintValue.create(3L, true));
110110
assertThat(protoMessageValue.select(StringValue.create("single_uint64")))
111-
.isEqualTo(UintValue.create(4L, false));
111+
.isEqualTo(UintValue.create(4L, true));
112112
assertThat(protoMessageValue.select(StringValue.create("single_double")))
113113
.isEqualTo(DoubleValue.create(5.5d));
114114
assertThat(protoMessageValue.select(StringValue.create("single_bool")))
@@ -178,9 +178,9 @@ public void newValue_createProtoMessage_wrappersPopulated() {
178178
assertThat(protoMessageValue.select(StringValue.create("single_int64_wrapper")).value())
179179
.isEqualTo(2L);
180180
assertThat(protoMessageValue.select(StringValue.create("single_uint32_wrapper")).value())
181-
.isEqualTo(3L);
181+
.isEqualTo(UnsignedLong.valueOf(3L));
182182
assertThat(protoMessageValue.select(StringValue.create("single_uint64_wrapper")).value())
183-
.isEqualTo(4L);
183+
.isEqualTo(UnsignedLong.valueOf(4L));
184184
assertThat(protoMessageValue.select(StringValue.create("single_double_wrapper")).value())
185185
.isEqualTo(5.5d);
186186
assertThat(protoMessageValue.select(StringValue.create("single_bool_wrapper")).value())

extensions/src/test/java/dev/cel/extensions/CelMathExtensionsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ public class CelMathExtensionsTest {
4444
CelOptions.current().enableUnsignedLongs(false).build();
4545
private static final CelCompiler CEL_COMPILER =
4646
CelCompilerFactory.standardCelCompilerBuilder()
47+
.setOptions(CEL_OPTIONS)
4748
.addLibraries(CelExtensions.math(CEL_OPTIONS))
4849
.build();
4950
private static final CelRuntime CEL_RUNTIME =
5051
CelRuntimeFactory.standardCelRuntimeBuilder()
52+
.setOptions(CEL_OPTIONS)
5153
.addLibraries(CelExtensions.math(CEL_OPTIONS))
5254
.build();
5355

testing/src/test/java/dev/cel/testing/EvalSyncTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.google.common.truth.Truth.assertThat;
1818

1919
import com.google.common.collect.ImmutableList;
20+
import com.google.common.primitives.UnsignedLong;
2021
import com.google.protobuf.Any;
2122
import com.google.protobuf.BoolValue;
2223
import com.google.protobuf.ByteString;
@@ -80,8 +81,8 @@ public static List<Object[]> data() {
8081
{StringValue.of("test"), "test"},
8182
{Int32Value.of(1), 1L},
8283
{Int64Value.of(1), 1L},
83-
{UInt32Value.of(1), 1L},
84-
{UInt64Value.of(1), 1L},
84+
{UInt32Value.of(1), UnsignedLong.valueOf(1L)},
85+
{UInt64Value.of(1), UnsignedLong.valueOf(1L)},
8586
{BytesValue.of(ByteString.copyFromUtf8("test")), ByteString.copyFromUtf8("test")},
8687
});
8788
}

0 commit comments

Comments
 (0)