camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [6/6] git commit: CAMEL-7303: Simple language accesing header with key quoted should unqoute, as headerAs does.
Date Tue, 18 Mar 2014 08:39:24 GMT
CAMEL-7303: Simple language accesing header with key quoted should unqoute, as headerAs does.


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

Branch: refs/heads/camel-2.12.x
Commit: 7569a4b1830842590d27de718925dd456711834d
Parents: c0d3d44
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Mar 18 09:25:10 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Mar 18 09:42:00 2014 +0100

----------------------------------------------------------------------
 .../simple/ast/SimpleFunctionExpression.java      | 10 ++++++----
 .../apache/camel/language/simple/SimpleTest.java  | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7569a4b1/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index 985857a..d02f050 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -268,19 +268,21 @@ public class SimpleFunctionExpression extends LiteralExpression {
             if (remainder.startsWith("[") && remainder.endsWith("]")) {
                 remainder = remainder.substring(1, remainder.length() - 1);
             }
+            // remove quotes from key
+            String key = StringHelper.removeLeadingAndEndingQuotes(remainder);
 
             // validate syntax
-            boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder);
+            boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(key);
             if (invalid) {
                 throw new SimpleParserException("Valid syntax: ${header.name[key]} was: "
+ function, token.getIndex());
             }
 
-            if (OgnlHelper.isValidOgnlExpression(remainder)) {
+            if (OgnlHelper.isValidOgnlExpression(key)) {
                 // ognl based header
-                return ExpressionBuilder.headersOgnlExpression(remainder);
+                return ExpressionBuilder.headersOgnlExpression(key);
             } else {
                 // regular header
-                return ExpressionBuilder.headerExpression(remainder);
+                return ExpressionBuilder.headerExpression(key);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7569a4b1/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index 407f755..c9e22a3 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -524,6 +524,24 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression("${in.headers}", headers);
     }
 
+    public void testHeaderKeyWithSpace() throws Exception {
+        Map<String, Object> headers = exchange.getIn().getHeaders();
+        headers.put("some key", "Some Value");
+        assertEquals(3, headers.size());
+
+        assertExpression("${headerAs(foo,String)}", "abc");
+        assertExpression("${headerAs(some key,String)}", "Some Value");
+        assertExpression("${headerAs('some key',String)}", "Some Value");
+
+        assertExpression("${header[foo]}", "abc");
+        assertExpression("${header[some key]}", "Some Value");
+        assertExpression("${header['some key']}", "Some Value");
+
+        assertExpression("${headers[foo]}", "abc");
+        assertExpression("${headers[some key]}", "Some Value");
+        assertExpression("${headers['some key']}", "Some Value");
+    }
+
     public void testHeaderAs() throws Exception {
         assertExpression("${headerAs(foo,String)}", "abc");
 


Mime
View raw message