E2E Bridge E2E Commerce

Suggestion: make String operation replace behave as documented.

E2E Forum Modeling & Development Suggestion: make String operation replace behave as documented.

This topic contains 2 replies, has 2 voices, and was last updated by  Ingo 1 month, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #3121


    Currently (in V6, I didn’t check V7 yet), the replace operation treats an empty string the same as a NULL: one gets the error “Cannot execute replace operations on undefined or empty strings.”

    This is annoying, since it goes counter to what the documentation says: “If the pattern does not match, the unchanged string will be returned.” and “All strings that correspond to the regular expression pattern will be replaced with the string replacement.”
    Yet, neither of the following works:

    local s = “”;
    set s = s.replace(“A+”, “B”); // no match case, result should be “”
    set s = s.replace(“A*”, “B”); // match case, result should be “B”

    It is also mathematically unsound and a behaviour that will surprise programmers in general, as there is, to my knowledge, no other programming language that would not allow pattern matches on empty strings. The more so as there are valid regular expressions that DO match an empty string. Hence, the implemented behaviour is comparable to having an addition operator that would raise an exception if the first operand was 0.

    Would it be possible to change the implementation according to the documentation?



    I’ll open an internal ticket for the problem, however, I cannot promise when and if it will be changed. Those functions have evolved historically and we first have to assess risks of breaking anything.



    Yes, that was my though also. There could be a Service that catches the exception to detect an empty string. However, this would be in reliance on non-documented behaviour.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.