You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2008/03/09 00:08:01 UTC

svn commit: r635110 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/util/SuperProperties.java test/java/org/apache/openejb/util/PropertiesTest.java test/java/org/apache/openejb/util/SuperPropertiesTest.java

Author: dain
Date: Sat Mar  8 15:07:56 2008
New Revision: 635110

URL: http://svn.apache.org/viewvc?rev=635110&view=rev
Log:
Add support for encoded separators and whitespace in SuperProperties key

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/PropertiesTest.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/SuperPropertiesTest.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java?rev=635110&r1=635109&r2=635110&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java Sat Mar  8 15:07:56 2008
@@ -534,7 +534,7 @@
                     break;
             }
 
-            if (Character.isWhitespace(nextChar)) {
+            if (nextByte >= 0 && Character.isWhitespace(nextChar)) {
                 // count leading white space
                 if (key.length() == 0) {
                     if (nextChar == '\t') {
@@ -550,6 +550,28 @@
                 }
             }
 
+            // Decode encoded separator characters
+            switch (nextByte) {
+                case ENCODED_EQUALS:
+                    nextChar = '=';
+                    break;
+                case ENCODED_COLON:
+                    nextChar = ':';
+                    break;
+                case ENCODED_SPACE:
+                    nextChar = ' ';
+                    break;
+                case ENCODED_TAB:
+                    nextChar = '\t';
+                    break;
+                case ENCODED_NEWLINE:
+                    nextChar = '\n';
+                    break;
+                case ENCODED_CARRIAGE_RETURN:
+                    nextChar = '\r';
+                    break;
+            }
+            
             inSeparator = false;
             if (value == null) {
                 key.append(nextChar);
@@ -577,10 +599,17 @@
 
     private static final int EOF = -1;
     private static final int LINE_ENDING = -4200;
+    private static final int ENCODED_EQUALS = -5000;
+    private static final int ENCODED_COLON = -5001;
+    private static final int ENCODED_SPACE = -5002;
+    private static final int ENCODED_TAB = -5003;
+    private static final int ENCODED_NEWLINE = -5004;
+    private static final int ENCODED_CARRIAGE_RETURN = -5005;
 
     private int decodeNextCharacter(InputStream in) throws IOException {
         boolean lineContinuation = false;
         boolean carriageReturnLineContinuation  = false;
+        boolean encoded  = false;
         while (true) {
             // read character
             int nextByte = in.read();
@@ -621,6 +650,7 @@
                         nextChar = readUnicode(in);
                         break;
                     default:
+                        encoded = true;
                         nextChar = decodeEscapeChar(nextChar);
                         break;
                 }
@@ -638,6 +668,22 @@
                 continue;
             }
 
+            if (encoded) {
+                switch (nextChar) {
+                    case '=':
+                        return ENCODED_EQUALS;
+                    case ':':
+                        return ENCODED_COLON;
+                    case ' ':
+                        return ENCODED_SPACE;
+                    case '\t':
+                        return ENCODED_TAB;
+                    case '\n':
+                        return ENCODED_NEWLINE;
+                    case '\r':
+                        return ENCODED_CARRIAGE_RETURN;
+                }
+            }
             return nextChar;
         }
     }
@@ -647,7 +693,7 @@
             case 'b':
                 return '\b';
             case 'f':
-                return'\f';
+                return '\f';
             case 'n':
                 return '\n';
             case 'r':

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/PropertiesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/PropertiesTest.java?rev=635110&r1=635109&r2=635110&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/PropertiesTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/PropertiesTest.java Sat Mar  8 15:07:56 2008
@@ -18,6 +18,8 @@
 package org.apache.openejb.util;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Properties;
@@ -303,6 +305,25 @@
         assertEquals(properties("foo", "b", "ar", ""), properties);
     }
 
+    public void testEscapedKeyValueSeparators() throws Exception {
+        Properties properties = createProperties();
+
+        // test put and get
+        properties.put("\t\r\n my: \t\n\rkey=", "foo");
+        assertEquals("foo", properties.get("\t\r\n my: \t\n\rkey="));
+
+        // test store
+        String text = store(properties);
+        if (text.startsWith("#")) text = text.split("\\n", 2)[1];
+        text = text.trim();
+        assertEquals("\\t\\r\\n\\ my\\:\\ \\t\\n\\rkey\\==foo", text);
+
+        // test load
+        properties = createProperties();
+        properties.load(new ByteArrayInputStream("\\t\\r\\n\\ my\\:\\ \\t\\n\\rkey\\==foo".getBytes()));
+        assertEquals("foo", properties.get("\t\r\n my: \t\n\rkey="));
+    }
+
     protected Properties createProperties() {
         return new Properties();
     }
@@ -347,5 +368,11 @@
         }
 
         fail(message.toString());
+    }
+
+    protected String store(Properties properties) throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        properties.store(out, null);
+        return new String(out.toByteArray());
     }
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/SuperPropertiesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/SuperPropertiesTest.java?rev=635110&r1=635109&r2=635110&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/SuperPropertiesTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/SuperPropertiesTest.java Sat Mar  8 15:07:56 2008
@@ -19,10 +19,8 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.Properties;
 
 public class SuperPropertiesTest extends PropertiesTest {
 
@@ -349,12 +347,6 @@
         assertEquals(singletonProperty("foo", "bar"), properties);
         assertEquals(4, properties.getIndent());
         assertEquals(2, properties.getCommentIndent());
-    }
-
-    protected String store(Properties properties) throws IOException {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        properties.store(out, null);
-        return new String(out.toByteArray());
     }
 
     protected SuperProperties createProperties() {