camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-6191: Simple predicate parser should keep whitespace in functions. Thanks to Antoine DESSAIGNE for the patch.
Date Fri, 17 May 2013 06:09:07 GMT
Updated Branches:
  refs/heads/camel-2.10.x ce7452c7e -> f8087e27b
  refs/heads/camel-2.11.x a2b1df78e -> 596d389aa


CAMEL-6191: Simple predicate parser should keep whitespace in functions. Thanks to Antoine
DESSAIGNE for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/596d389a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/596d389a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/596d389a

Branch: refs/heads/camel-2.11.x
Commit: 596d389aac5e21bf725246ee6255cfe50faad503
Parents: a2b1df7
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri May 17 08:03:53 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri May 17 08:04:52 2013 +0200

----------------------------------------------------------------------
 .../language/simple/SimplePredicateParser.java     |   13 ++++++++++---
 .../language/simple/SimpleParserPredicateTest.java |    8 ++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/596d389a/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
b/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
index eae8296..44f7cc0 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
@@ -287,16 +287,23 @@ public class SimplePredicateParser extends BaseSimpleParser {
      * which makes the succeeding parsing easier.
      */
     private void removeIgnorableWhiteSpaceTokens() {
-        // white space can be removed if its not part of a quoted text
+        // white space can be removed if its not part of a quoted text or within function(s)
         boolean quote = false;
+        int functionCount = 0;
 
         Iterator<SimpleToken> it = tokens.iterator();
         while (it.hasNext()) {
             SimpleToken token = it.next();
             if (token.getType().isSingleQuote()) {
                 quote = !quote;
-            } else if (token.getType().isWhitespace() && !quote) {
-                it.remove();
+            } else if (!quote) {
+                if (token.getType().isFunctionStart()) {
+                    functionCount++;
+                } else if (token.getType().isFunctionEnd()) {
+                    functionCount--;
+                } else if (token.getType().isWhitespace() && functionCount == 0)
{
+                    it.remove();
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/596d389a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
index 020a286..f089afa 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
@@ -180,7 +180,7 @@ public class SimpleParserPredicateTest extends ExchangeTestSupport {
 
         assertTrue("Should match", pre.matches(exchange));
     }
-    
+
     public void testSimpleExpressionPredicate() throws Exception {
         exchange.getIn().setBody("Hello");
         exchange.getIn().setHeader("number", "1234");
@@ -203,6 +203,10 @@ public class SimpleParserPredicateTest extends ExchangeTestSupport {
         parser = new SimplePredicateParser("${body['foo bar']} == 456", true);
         pre = parser.parsePredicate();
         assertTrue("Should match", pre.matches(exchange));
-    }
 
+        // the predicate has whitespace in the function
+        parser = new SimplePredicateParser("${body[foo bar]} == 456", true);
+        pre = parser.parsePredicate();
+        assertTrue("Should match", pre.matches(exchange));
+    }
 }


Mime
View raw message