tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject incubator-tamaya git commit: TAMAYA-127: Fixed resolver issues.
Date Tue, 08 Dec 2015 23:21:25 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 166a11448 -> 5fa2934af


TAMAYA-127: Fixed resolver issues.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/5fa2934a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/5fa2934a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/5fa2934a

Branch: refs/heads/master
Commit: 5fa2934afe7f8bff460fd4db6d1662358563b2b8
Parents: 166a114
Author: anatole <anatole@apache.org>
Authored: Wed Dec 9 00:21:16 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Wed Dec 9 00:21:16 2015 +0100

----------------------------------------------------------------------
 .../internal/DefaultExpressionEvaluator.java    | 27 +++++++-----------
 .../tamaya/resolver/ConfigResolutionTest.java   | 30 ++++++++++++++++++++
 .../tamaya/resolver/MyTestPropertySource.java   |  8 ++++++
 3 files changed, 48 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5fa2934a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
index 575a176..3a2e0f1 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
@@ -127,36 +127,29 @@ public class DefaultExpressionEvaluator implements ExpressionEvaluator
{
         if(value ==null){
             return null;
         }
-        StringTokenizer tokenizer = new StringTokenizer(value, "${}\\", true);
-        boolean escaped = false;
+        StringTokenizer tokenizer = new StringTokenizer(value, "${}", true);
         StringBuilder resolvedValue = new StringBuilder();
         StringBuilder current = new StringBuilder();
         while (tokenizer.hasMoreTokens()) {
             String token = tokenizer.nextToken();
-            if (escaped) {
-                current.append(token);
-                escaped = false;
-            } else {
                 switch (token) {
-                    case "\\":
-                        escaped = true;
-                        current.append("\\");
-                        break;
                     case "$":
-                        if (current.length() > 0) {
-                            resolvedValue.append(current);
-                            current.setLength(0);
+                        String nextToken = tokenizer.hasMoreTokens()?tokenizer.nextToken():"";
+                        if (!"{".equals(nextToken)) {
+                            current.append(token);
+                            current.append(nextToken);
+                            break;
                         }
-                        if (!"{".equals(tokenizer.nextToken())) {
-                            LOG.warning("Invalid expression syntax in: " + value);
-                            return value;
+                        if(value.indexOf('}')<=0){
+                            current.append(token);
+                            current.append(nextToken);
+                            break;
                         }
                         String subExpression = parseSubExpression(tokenizer, value);
                         current.append(evaluateInternal(subExpression));
                         break;
                     default:
                         current.append(token);
-                }
             }
         }
         if (current.length() > 0) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5fa2934a/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
b/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
index 7e3db08..5f3306a 100644
--- a/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
+++ b/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
@@ -42,6 +42,36 @@ public class ConfigResolutionTest {
     }
 
     @Test
+    public void test_Prefix_Resolution_BadSyntax1() {
+        assertEquals(ConfigurationProvider.getConfiguration().get("Will fail1."), "V$java.version");
+    }
+
+    @Test
+    public void test_Prefix_Resolution_BadSyntax2() {
+        assertEquals(ConfigurationProvider.getConfiguration().get("Will fail2."), "V$java.version}");
+    }
+
+    @Test
+    public void test_Prefix_Resolution_BadSyntax31() {
+        assertEquals(ConfigurationProvider.getConfiguration().get("Will not fail3."), "V${java.version");
+    }
+
+    @Test
+    public void test_Prefix_Resolution_Escaped1() {
+        assertEquals(ConfigurationProvider.getConfiguration().get("Will not fail1."), "V$\\{java.version");
+    }
+
+    @Test
+    public void test_Prefix_Resolution_Escaped2() {
+        assertEquals(ConfigurationProvider.getConfiguration().get("Will not fail2."), "V\\${java.version");
+    }
+
+    @Test
+    public void test_Prefix_Resolution_EnvKeys() {
+        assertEquals(ConfigurationProvider.getConfiguration().get("env.keys"), System.getProperty("java.version")
+ " plus $java.version");
+    }
+
+    @Test
     public void test_Prefix_ExpressionOnly_Resolution() {
         assertEquals(ConfigurationProvider.getConfiguration().get("Expression Only"), System.getProperty("java.version"));
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5fa2934a/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
b/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
index d32b88a..3ed4650 100644
--- a/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
+++ b/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
@@ -50,6 +50,14 @@ public class MyTestPropertySource implements PropertySource{
         properties.put("config-ref2", "Config Ref 2 -> Ref 1: ${conf:config-ref}");
         properties.put("config-ref3", "Config Ref 3 -> Ref 2: ${conf:config-ref2}");
 
+        properties.put("Will fail1.", "V$java.version");
+        properties.put("Will fail2.", "V$java.version}");
+        properties.put("Will not fail3.", "V${java.version");
+        properties.put("Will not fail1.", "V$\\{java.version");
+        properties.put("Will not fail2.", "V\\${java.version");
+
+        properties.put("env.keys", "${java.version} plus $java.version");
+
         properties.put("escaped", "Config Ref 3 -> Ref 2: \\${conf:config-ref2 will not
be evaluated and will not contain\\t tabs \\n " +
                 "newlines or \\r returns...YEP!");
     }


Mime
View raw message