felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1547764 - in /felix/trunk/utils/src: main/java/org/apache/felix/utils/properties/Properties.java test/java/org/apache/felix/utils/properties/PropertiesTest.java
Date Wed, 04 Dec 2013 11:18:43 GMT
Author: gnodet
Date: Wed Dec  4 11:18:43 2013
New Revision: 1547764

URL: http://svn.apache.org/r1547764
Log:
[FELIX-4341] The Properties object does not follow the spec wrt spaces

Modified:
    felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
    felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java

Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java?rev=1547764&r1=1547763&r2=1547764&view=diff
==============================================================================
--- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java (original)
+++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java Wed
Dec  4 11:18:43 2013
@@ -755,7 +755,10 @@ public class Properties extends Abstract
                 }
 
                 valueLines.add(line);
-                line = line.trim();
+                while (line.length() > 0 && contains(WHITE_SPACE, line.charAt(0)))
+                {
+                    line = line.substring(1, line.length());
+                }
 
                 if (checkCombineLines(line))
                 {
@@ -880,7 +883,8 @@ public class Properties extends Abstract
             // 0: key parsing
             // 1: antislash found while parsing the key
             // 2: separator crossing
-            // 3: value parsing
+            // 3: white spaces
+            // 4: value parsing
             int state = 0;
 
             for (int pos = 0; pos < line.length(); pos++)
@@ -946,19 +950,36 @@ public class Properties extends Abstract
                             value.append(c);
 
                             // switch to the value parsing state
-                            state = 3;
+                            state = 4;
                         }
 
                         break;
 
                     case 3:
+                        if (contains(WHITE_SPACE, c))
+                        {
+                            // do nothing, eat all white spaces
+                            state = 3;
+                        }
+                        else
+                        {
+                            // any other character indicates we encoutered the beginning
of the value
+                            value.append(c);
+
+                            // switch to the value parsing state
+                            state = 4;
+                        }
+
+                        break;
+
+                    case 4:
                         value.append(c);
                         break;
                 }
             }
 
-            result[0] = key.toString().trim();
-            result[1] = value.toString().trim();
+            result[0] = key.toString();
+            result[1] = value.toString();
 
             return result;
         }

Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java?rev=1547764&r1=1547763&r2=1547764&view=diff
==============================================================================
--- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
(original)
+++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
Wed Dec  4 11:18:43 2013
@@ -54,6 +54,73 @@ public class PropertiesTest extends Test
         properties.load(this.getClass().getClassLoader().getResourceAsStream(TEST_PROPERTIES_FILE));
     }
 
+    public void testSpaces() throws Exception {
+        String config = "\n" +
+                        "\n" +
+                        "    \n" +
+                        "                \n" +
+                        "   \\ \\r \\n \\t \\f\n" +
+                        "   \n" +
+                        "                                                \n" +
+                        "! dshfjklahfjkldashgjl;as\n" +
+                        "     #jdfagdfjagkdjfghksdajfd\n" +
+                        "     \n" +
+                        "!!properties\n" +
+                        "\n" +
+                        "a=a\n" +
+                        "b bb as,dn   \n" +
+                        "c\\r\\ \\t\\nu =:: cu\n" +
+                        "bu= b\\\n" +
+                        "                u\n" +
+                        "d=d\\r\\ne=e\n" +
+                        "f   :f\\\n" +
+                        "f\\\n" +
+                        "                        f\n" +
+                        "g               g\n" +
+                        "h\\u0020h\n" +
+                        "\\   i=i\n" +
+                        "j=\\   j\n" +
+                        "space=\\   c\n" +
+                        "\n" +
+                        "dblbackslash=\\\\\n" +
+                        "                        \n";
+
+        java.util.Properties props1 = new java.util.Properties();
+        props1.load(new StringReader(config));
+
+        org.apache.felix.utils.properties.Properties props2 = new org.apache.felix.utils.properties.Properties();
+        props2.load(new StringReader(config));
+
+        assertEquals("1", "\n \t \f", props1.getProperty(" \r"));
+        assertEquals("2", "a", props1.getProperty("a"));
+        assertEquals("3", "bb as,dn   ", props1.getProperty("b"));
+        assertEquals("4", ":: cu", props1.getProperty("c\r \t\nu"));
+        assertEquals("5", "bu", props1.getProperty("bu"));
+        assertEquals("6", "d\r\ne=e", props1.getProperty("d"));
+        assertEquals("7", "fff", props1.getProperty("f"));
+        assertEquals("8", "g", props1.getProperty("g"));
+        assertEquals("9", "", props1.getProperty("h h"));
+        assertEquals("10", "i=i", props1.getProperty(" "));
+        assertEquals("11", "   j", props1.getProperty("j"));
+        assertEquals("12", "   c", props1.getProperty("space"));
+        assertEquals("13", "\\", props1.getProperty("dblbackslash"));
+
+        assertEquals("1", "\n \t \f", props2.getProperty(" \r"));
+        assertEquals("2", "a", props2.getProperty("a"));
+        assertEquals("3", "bb as,dn   ", props2.getProperty("b"));
+        assertEquals("4", ":: cu", props2.getProperty("c\r \t\nu"));
+        assertEquals("5", "bu", props2.getProperty("bu"));
+        assertEquals("6", "d\r\ne=e", props2.getProperty("d"));
+        assertEquals("7", "fff", props2.getProperty("f"));
+        assertEquals("8", "g", props2.getProperty("g"));
+        assertEquals("9", "", props2.getProperty("h h"));
+        assertEquals("10", "i=i", props2.getProperty(" "));
+        assertEquals("11", "   j", props2.getProperty("j"));
+        assertEquals("12", "   c", props2.getProperty("space"));
+        assertEquals("13", "\\", props2.getProperty("dblbackslash"));
+        assertEquals(props1, props2);
+    }
+
     /**
      * <p>
      * Test getting property.



Mime
View raw message