[FELIX-4341] The Properties object does not follow the spec wrt spaces
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1547764 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/utils/src/main/java/org/apache/felix/utils/properties/Properties.java b/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
index c8ca0eb..bb15907 100644
--- a/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
+++ b/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
@@ -755,7 +755,10 @@
}
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 @@
// 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 @@
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;
}
diff --git a/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java b/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
index 55249ee..ecef3ac 100644
--- a/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
+++ b/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
@@ -54,6 +54,73 @@
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.