1818import dev .cel .bundle .Cel ;
1919import dev .cel .bundle .CelFactory ;
2020import dev .cel .checker .CelCheckerBuilder ;
21+ import dev .cel .checker .CelCheckerLegacyImpl ;
2122import dev .cel .checker .CelStandardDeclarations ;
2223import dev .cel .common .CelOptions ;
2324import dev .cel .common .CelVarDecl ;
2425import dev .cel .common .types .SimpleType ;
26+ import dev .cel .compiler .CelCompiler ;
27+ import dev .cel .compiler .CelCompilerImpl ;
2528import dev .cel .compiler .CelCompilerLibrary ;
2629import dev .cel .extensions .CelExtensions ;
2730import dev .cel .parser .CelParserBuilder ;
31+ import dev .cel .parser .CelParserImpl ;
2832import dev .cel .parser .CelStandardMacro ;
33+ import dev .cel .runtime .CelRuntime ;
2934import dev .cel .runtime .CelRuntimeBuilder ;
35+ import dev .cel .runtime .CelRuntimeImpl ;
3036import dev .cel .runtime .CelRuntimeLibrary ;
3137import dev .cel .runtime .CelStandardFunctions ;
3238import java .util .concurrent .ConcurrentHashMap ;
3844 */
3945final class ValidateLibrary implements CelCompilerLibrary , CelRuntimeLibrary {
4046
41- private static final CelOptions CEL_OPTIONS = CelOptions .DEFAULT ;
47+ private static final CelOptions CEL_OPTIONS =
48+ CelOptions .current ().enableHeterogeneousNumericComparisons (true ).build ();
4249
4350 private final ConcurrentMap <String , Pattern > patternCache = new ConcurrentHashMap <>();
4451
@@ -47,22 +54,32 @@ final class ValidateLibrary implements CelCompilerLibrary, CelRuntimeLibrary {
4754
4855 static Cel newCel () {
4956 ValidateLibrary validateLibrary = new ValidateLibrary ();
50- return CelFactory .standardCelBuilder ()
51- .setOptions (CEL_OPTIONS )
52- // Drop stdlib matches; CustomOverload provides a caching replacement.
53- // Ref: https://github.com/google/cel-java/issues/1038
54- .setStandardEnvironmentEnabled (false )
55- .setStandardDeclarations (
56- CelStandardDeclarations .newBuilder ()
57- .excludeFunctions (CelStandardDeclarations .StandardFunction .MATCHES )
58- .build ())
59- .setStandardFunctions (
60- CelStandardFunctions .newBuilder ()
61- .excludeFunctions (CelStandardFunctions .StandardFunction .MATCHES )
62- .build ())
63- .addCompilerLibraries (validateLibrary , CelExtensions .strings ())
64- .addRuntimeLibraries (validateLibrary , CelExtensions .strings ())
65- .build ();
57+ // Wired by hand instead of via plannerCelBuilder(): CelRuntimeImpl directs callers to subset
58+ // stdlib via setStandardFunctions rather than setStandardEnvironmentEnabled, so the runtime
59+ // does that while the checker uses setStandardEnvironmentEnabled(false).
60+ CelCompiler compiler =
61+ CelCompilerImpl .newBuilder (
62+ CelParserImpl .newBuilder (),
63+ CelCheckerLegacyImpl .newBuilder ().setStandardEnvironmentEnabled (false ))
64+ .setOptions (CEL_OPTIONS )
65+ // Drop stdlib matches; CustomOverload provides a caching replacement.
66+ // Ref: https://github.com/google/cel-java/issues/1038
67+ .setStandardDeclarations (
68+ CelStandardDeclarations .newBuilder ()
69+ .excludeFunctions (CelStandardDeclarations .StandardFunction .MATCHES )
70+ .build ())
71+ .addLibraries (validateLibrary , CelExtensions .strings ())
72+ .build ();
73+ CelRuntime runtime =
74+ CelRuntimeImpl .newBuilder ()
75+ .setOptions (CEL_OPTIONS )
76+ .setStandardFunctions (
77+ CelStandardFunctions .newBuilder ()
78+ .excludeFunctions (CelStandardFunctions .StandardFunction .MATCHES )
79+ .build ())
80+ .addLibraries (validateLibrary , CelExtensions .strings ())
81+ .build ();
82+ return CelFactory .combine (compiler , runtime );
6683 }
6784
6885 @ Override
0 commit comments