Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13962

OgnlHelper.splitOgnl not able to handle Regex properly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.24.1, 3.0.0.RC1
    • Fix Version/s: 3.0.0.RC2, 3.0.0
    • Component/s: camel-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      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 contained within the headers:

          @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));
          }
      

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                acosentino Andrea Cosentino
                Reporter:
                paetzold.michael@gmail.com Michael P├Ątzold
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m