Author: oheger
Date: Thu May 24 13:43:18 2007
New Revision: 541423
URL: http://svn.apache.org/viewvc?view=rev&rev=541423
Log:
CONFIGURATION-274: Support escaping the escape character for list delimiters in
PropertiesConfiguration
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java?view=diff&rev=541423&r1=541422&r2=541423
==============================================================================
---
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
(original)
+++
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
Thu May 24 13:43:18 2007
@@ -185,6 +185,9 @@
/** Constant for the platform specific line separator.*/
private static final String LINE_SEPARATOR =
System.getProperty("line.separator");
+ /** Constant for the escaping character.*/
+ private static final String ESCAPE = "\\";
+
/** Constant for the radix of hex numbers.*/
private static final int HEX_RADIX = 16;
@@ -933,7 +936,7 @@
String escapedValue =
StringEscapeUtils.escapeJava(String.valueOf(value));
if (delimiter != 0)
{
- escapedValue = StringUtils.replace(escapedValue,
String.valueOf(delimiter), "\\" + delimiter);
+ escapedValue = StringUtils.replace(escapedValue,
String.valueOf(delimiter), ESCAPE + delimiter);
}
return escapedValue;
}
@@ -950,11 +953,20 @@
if (!values.isEmpty())
{
Iterator it = values.iterator();
- StringBuffer buf = new StringBuffer(escapeValue(it.next()));
+ String lastValue = escapeValue(it.next());
+ StringBuffer buf = new StringBuffer(lastValue);
while (it.hasNext())
{
+ // if the last value ended with an escape character, it has
+ // to be escaped itself; otherwise the list delimiter will
+ // be escaped
+ if (lastValue.endsWith(ESCAPE))
+ {
+ buf.append(ESCAPE).append(ESCAPE);
+ }
buf.append(delimiter);
- buf.append(escapeValue(it.next()));
+ lastValue = escapeValue(it.next());
+ buf.append(lastValue);
}
return buf.toString();
}
Modified:
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java?view=diff&rev=541423&r1=541422&r2=541423
==============================================================================
---
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
(original)
+++
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
Thu May 24 13:43:18 2007
@@ -174,7 +174,7 @@
// reload the configuration
Configuration config2 = new PropertiesConfiguration(url);
- assertEquals("true", config2.getString("configuration.loaded"));
+ assertEquals("true", config2.getString("configuration.loaded"));
}
public void testSaveToHTTPServer() throws Exception
@@ -234,7 +234,7 @@
// reload the configuration
Configuration config2 = new PropertiesConfiguration(url);
- assertEquals("true", config2.getString("configuration.loaded"));
+ assertEquals("true", config2.getString("configuration.loaded"));
}
public void testInMemoryCreatedSave() throws Exception
@@ -323,6 +323,27 @@
conf.setFileName(testSavePropertiesFile.getName());
conf.save();
assertTrue(testSavePropertiesFile.exists());
+ }
+
+ /**
+ * Tests whether the escape character for list delimiters can be itself
+ * escaped and survives a save operation.
+ */
+ public void testSaveEscapedEscapingCharacter()
+ throws ConfigurationException
+ {
+ conf.addProperty("test.dirs", "C:\\Temp\\\\,D:\\Data\\\\,E:\\Test\\");
+ List dirs = conf.getList("test.dirs");
+ assertEquals("Wrong number of list elements", 3, dirs.size());
+ if (testSavePropertiesFile.exists())
+ {
+ assertTrue(testSavePropertiesFile.delete());
+ }
+ conf.save(testSavePropertiesFile);
+
+ PropertiesConfiguration checkConfig = new PropertiesConfiguration(
+ testSavePropertiesFile);
+ ConfigurationAssert.assertEquals(conf, checkConfig);
}
public void testLoadViaProperty() throws Exception
Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=541423&r1=541422&r2=541423
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Thu May 24
13:43:18 2007
@@ -23,6 +23,10 @@
<body>
<release version="1.5-SNAPSHOT" date="in SVN" description="">
+ <action dev="oheger" type="fix" issue="CONFIGURATION-274">
+ PropertiesConfiguration now supports escaping the escape character for
+ list delimiters.
+ </action>
<action dev="ebourg" type="fix" issue="CONFIGURATION-269">
PropertiesConfiguration no longer escape the list delimiter on saving
if the list delimiter has been disabled.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]