commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "B (JIRA)" <>
Subject [jira] Created: (CONFIGURATION-440) setProperty in XmlConfiguration escapes backslashes
Date Thu, 03 Mar 2011 09:42:37 GMT
setProperty in XmlConfiguration escapes backslashes

                 Key: CONFIGURATION-440
             Project: Commons Configuration
          Issue Type: Bug
          Components: Build
    Affects Versions: 1.6
         Environment: Windows 7
            Reporter: B
             Fix For: 2.0

When setPropery sets a new value that has backslashes (like path), backslashes are escaped.
When that value is loaded again, all backslashes are duplicated. 

public class XmlConfigurationTest {

    private static final String XML_CONFIGURATION_PATH = "resources/xml/config.xml";

    private static final String PATH1 = "c:\\temp\\path\\file.txt";

    private static final String PATH2 = "c:\\temp1\\path1\\file1.txt";

    private static final String PATH3 = "c:\\temp2\\path2\\file2.txt";

    public void testXmlConfiguration() throws IOException {
	File resourceFile = null;
	try {

	    resourceFile = new File(SystemUtils.getTargetDirectory(),

	    String value = null;

	    XMLConfiguration configuration = new XMLConfiguration();
	    configuration.setExpressionEngine(new XPathExpressionEngine());
	    configuration.addProperty(" key1", PATH1);
	    configuration.setProperty(" key2", PATH2);;
            /* All values are saved with non escaped backslashes */

	    value = configuration.getString("key1");
	    assertEquals(value, PATH1);
	    value = configuration.getString("key2");
	    assertEquals(value, PATH2);

	     * Set again same property with different value. Setting property
	     * with this configuration will escape backslashes. Even though
	     * assert will pass, path with escaped backslashes will be written
	     * in a file (don't know if it is setProperty or save that is causing troubles).
	    configuration.setProperty(" key2", PATH3);;
	    value = configuration.getString("key2");
	    assertEquals(value, PATH3);

	     * Create new configuration and load values from previously saved
	     * file.
	    XMLConfiguration newConfiguration = new XMLConfiguration();
	    newConfiguration.setExpressionEngine(new XPathExpressionEngine());

	     * At this point, configuration will load escaped backslashes, and
	     * the test will fail.
	    value = newConfiguration.getString("key2");
	    assertEquals(value, PATH3);

	} catch (Throwable e) {
	} finally {
	     * Delete resource file


This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message