camunda / feel-scala

FEEL parser and interpreter written in Scala
https://camunda.github.io/feel-scala/
Apache License 2.0
119 stars 46 forks source link

The evaluation of `substring()` fails if the length is greater than the given string #801

Open saig0 opened 5 months ago

saig0 commented 5 months ago

Describe the bug If I invoke the substring() function with a length that is greater than the given string then the evaluation fails and reports a Java StringIndexOutOfBoundsException.

To Reproduce Steps to reproduce the behavior:

  1. Evaluate the expression substring("abc", 1, 4)
  2. Verify that the evaluation fails with the message
failed to evaluate expression 'substring("abc", 1, 4)' :
 java.lang.StringIndexOutOfBoundsException: begin 0, end 4, length 3

Expected behavior

The function invocation should return the whole string if the length is greater than the string.

substring("abc", 1, 4)    // --> "abc"

However, according to the DMN 1.5 specification, the function invocation should return null.

Screenshot from 2024-02-01 15-26-04

However, returning null is not the most (business) user-friendly behavior. It could lead to complicated expressions, for example:

if string length(message) < 10 then message else substring(message, 1, 10)

Environment