Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Support CelOptions to disable string conversion and list/string concatenation #502

Copy link
Copy link

Description

@sergiitk
Issue body actions

Feature request checklist

  • There are no issues that match the desired change
  • The change is large enough it can't be addressed with a simple Pull Request
  • If this is a bug, please file a Bug Report.

Change
To make CEL environment setup consistent across CEL implementations, I propose to add equivalent runtime options that control string conversion and list/string concatenation equivalent to those found in CEL-cpp:

// Enable string() overloads.
bool enable_string_conversion = true;

// Enable string concatenation overload.
bool enable_string_concat = true;

// Enable list concatenation overload.
bool enable_list_concat = true;

Example

CelCompiler CEL_COMPILER = CelCompilerFactory.standardCelCompilerBuilder()
    .setResultType(SimpleType.BOOL)
    .build();

@Test
public void cel_stringConversionDisabled() throws Exception {
  CelRuntime CEL_RUNTIME = CelRuntimeFactory.standardCelRuntimeBuilder()
      .setOptions(CelOptions.current().enableStringConversion(false).build())
      .build();

  // TODO: verify conversions to all types.
  String expr = "string(3.14) == '3.14'";
  CelRuntime.Program program = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());
  CelEvaluationException celErr = assertThrows(CelEvaluationException.class, program::eval);
  assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}

@Test
public void cel_stringConcatDisabled() throws Exception {
  CelRuntime CEL_RUNTIME = CelRuntimeFactory.standardCelRuntimeBuilder()
      .setOptions(CelOptions.current().enableStringConcat(false).build())
      .build();

  String expr = "'ab' + 'cd' == 'abcd'";
  CelRuntime.Program program = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());
  CelEvaluationException celErr = assertThrows(CelEvaluationException.class, program::eval);
  assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}

@Test
public void cel_listConcatDisabled() throws Exception {
  CelRuntime CEL_RUNTIME = CelRuntimeFactory.standardCelRuntimeBuilder()
      .setOptions(CelOptions.current().enableListConcat(false).build())
      .build();

  String expr = "size([1, 2] + [3, 4]) == 4";
  CelRuntime.Program program = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());
  CelEvaluationException celErr = assertThrows(CelEvaluationException.class, program::eval);
  assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}

Related

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.