Michael Pätzold created CAMEL-13962:
---------------------------------------

             Summary: OgnlHelper.splitOgnl not able to handle Regex properly
                 Key: CAMEL-13962
                 URL: https://issues.apache.org/jira/browse/CAMEL-13962
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 3.0.0.RC1, 2.24.1
            Reporter: Michael Pätzold


The splitOgnl method cannot properly handle an expression if it contains 
numerous paranthesis brackets and dots what is very likely in case you want to 
use regular expressions.

The following examples tries to extract a specific cookie value from the cookie 
string that's containes within the headers:

{code:java}
    @Test
    public void splitOgnlWithRegexInMethod() {
        String ognl = 
"header.cookie.replaceFirst(\".*;?iwanttoknow=([^;]+);?.*\", \"$1\")";
        assertFalse(OgnlHelper.isInvalidValidOgnlExpression(ognl));
        assertTrue(OgnlHelper.isValidOgnlExpression(ognl));

        List<String> strings = OgnlHelper.splitOgnl(ognl);
        assertEquals(3, strings.size());
        assertEquals("header", strings.get(0));
        assertEquals(".cookie", strings.get(1));
        assertEquals(".replaceFirst(\".*;?iwanttoknow=([^;]+);?.*\", \"$1\")", 
strings.get(2));
    }
{code}

The test fails using the current code base since the regular expression itself 
is split at the first dot after the first closing paranthesis bracket.

If you'll agree that this is a bug I can come up with a possible solution that 
takes the amount of opening/closing brackets into account via PR.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to