You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2011/02/09 22:12:55 UTC
svn commit: r1069110 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/INIConfiguration.java
test/java/org/apache/commons/configuration2/TestINIConfiguration.java
Author: oheger
Date: Wed Feb 9 21:12:54 2011
New Revision: 1069110
URL: http://svn.apache.org/viewvc?rev=1069110&view=rev
Log:
[CONFIGURATION-434] Allow comment characters to be part of property values. To be recognized as a comment character, the character must be preceded by whitespace. Ported fix to configuration2 branch.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/INIConfiguration.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/INIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/INIConfiguration.java?rev=1069110&r1=1069109&r2=1069110&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/INIConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/INIConfiguration.java Wed Feb 9 21:12:54 2011
@@ -382,6 +382,12 @@ public class INIConfiguration extends Ab
* <pre>
* 'value' ; comment -> value
* </pre>
+ * Note that a comment character is only recognized if there is at least one
+ * whitespace character before it. So it can appear in the property value,
+ * e.g.:
+ * <pre>
+ * C:\\Windows;C:\\Windows\\system32
+ * </pre>
*
* @param val the value to be parsed
* @param reader the reader (needed if multiple lines have to be read)
@@ -404,6 +410,7 @@ public class INIConfiguration extends Ab
int i = quoted ? 1 : 0;
StringBuilder result = new StringBuilder();
+ char lastChar = 0;
while (i < value.length() && !stop)
{
char c = value.charAt(i);
@@ -436,17 +443,18 @@ public class INIConfiguration extends Ab
}
else
{
- if (!isCommentChar(c))
+ if (isCommentChar(c) && Character.isWhitespace(lastChar))
{
- result.append(c);
+ stop = true;
}
else
{
- stop = true;
+ result.append(c);
}
}
i++;
+ lastChar = c;
}
String v = result.toString();
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java?rev=1069110&r1=1069109&r2=1069110&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java Wed Feb 9 21:12:54 2011
@@ -726,4 +726,24 @@ public class TestINIConfiguration extend
assertEquals("Wrong value (2)", "test2", conf.getString(section
+ ".test2"));
}
+
+ /**
+ * Tests whether a value which contains a semicolon can be loaded
+ * successfully. This test is related to CONFIGURATION-434.
+ */
+ public void testValueWithSemicolon() throws ConfigurationException
+ {
+ final String path =
+ "C:\\Program Files\\jar\\manage.jar;"
+ + "C:\\Program Files\\jar\\guiLauncher.jar";
+ final String content =
+ "[Environment]" + LINE_SEPARATOR + "Application Type=any"
+ + LINE_SEPARATOR + "Class Path=" + path + " ;comment"
+ + LINE_SEPARATOR + "Path=" + path
+ + "\t; another comment";
+ INIConfiguration config = setUpConfig(content);
+ assertEquals("Wrong class path", path,
+ config.getString("Environment.Class Path"));
+ assertEquals("Wrong path", path, config.getString("Environment.Path"));
+ }
}