You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Harish Annamalai (Jira)" <ji...@apache.org> on 2024/09/05 13:50:00 UTC

[jira] [Created] (CAMEL-21180) > Simple Expression fails when OGNL replaceALL is used with regular expression of Escape Sequences

Harish Annamalai created CAMEL-21180:
----------------------------------------

             Summary: > Simple Expression fails when OGNL replaceALL is used with regular expression of Escape Sequences
                 Key: CAMEL-21180
                 URL: https://issues.apache.org/jira/browse/CAMEL-21180
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 3.22.0
            Reporter: Harish Annamalai


We have come across a special case when Simple Expression is used to invoke OGNL replaceAll of String method with regex. The expression evaluation fails when the replaceAll is called with a regular Expression with only Special Character such as [\\r\\n] .

Examples 1:

{{        from("timer:getter?period=1000&repeatCount=1")}}
{{                .setBody(constant("foobar\nfoobar"))}}
{{                .setBody(simple("${body.replaceAll('[o\\r\\n]','')}"))}}
{{                .to("log://expr")}}
{{                .end();}}
{{Output:}}

{{[ timer://getter] expr                                     : Exchange[ExchangePattern: InOnly, BodyType: String, Body: fbarfbar]}}
{{Here the replaceAll works correctly.}}

However, in Example 2:

{{        from("timer:getter?period=1000&repeatCount=1")}}
{{                .setBody(constant("foobar\nfoobar"))}}
{{                .setBody(simple("${body.replaceAll('[\\r\\n]','')}"))}}
{{                .to("log://onlyspecial")}}
{{                .end();}}
{{The Example 2 fails with expression:}}
{{Caused by: java.lang.IllegalArgumentException: name must be specified and not empty}}

We find it strange because when the replaceAll Simple expression itself creates a new line in case of [\\r\\n] while it handles it correctly if the expression is \\r\\n.
using a valid regular expression [\\r\\n] fails, while `\\r\\n' works correctly.

We are using Camel 3.x and we have used bodyOneLine as an alternative. However, the OGNL expression seems to behave weirdly when it is used within Square Brackets , for example [\\t] also fails in ${body.replaceAll('[\\t]','')}

It appears simple expression parser is unable to handle only Escape Sequences, even [o\\t] works.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)