Summary
The CEL specification (section 6.2.5) defines string.contains(string) -> bool as a standard string function. Currently, calling .contains() on a StringType raises CELEvalError: no such overload in cel-python.
Steps to reproduce
importcelpyenv=celpy.Environment()
ast=env.compile('"hello world".contains("world")')
prog=env.program(ast)
result=prog.evaluate({})
print(result) # Expected: trueActual behaviour
celpy.celenv.CELEvalError: no such overload
Expected behaviour
contains() should return true when the substring is present and false otherwise, matching the Go and Java CEL implementations.
Proposed fix
Add a contains method to StringType in src/celpy/celtypes.py:
defcontains(self, other: 'StringType') ->BoolType:
returnBoolType(str(other) instr(self))
And register the overload in the function dispatch table so that "x".contains("y") is correctly dispatched.
Related
Summary
The CEL specification (section 6.2.5) defines
string.contains(string) -> boolas a standard string function. Currently, calling.contains()on aStringTyperaisesCELEvalError: no such overloadin cel-python.Steps to reproduce
Actual behaviour
Expected behaviour
contains()should returntruewhen the substring is present andfalseotherwise, matching the Go and Java CEL implementations.Proposed fix
Add a
containsmethod toStringTypeinsrc/celpy/celtypes.py:And register the overload in the function dispatch table so that
"x".contains("y")is correctly dispatched.Related
.contains()not working)