You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "B (JIRA)" <ji...@apache.org> on 2011/03/03 10:42:37 UTC

[jira] Created: (CONFIGURATION-440) setProperty in XmlConfiguration escapes backslashes

setProperty in XmlConfiguration escapes backslashes
---------------------------------------------------

                 Key: CONFIGURATION-440
                 URL: https://issues.apache.org/jira/browse/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";

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

	    assertNotNull(_bundleContext);
	    resourceFile = new File(SystemUtils.getTargetDirectory(),
		    XML_CONFIGURATION_PATH);
	    assertTrue(resourceFile.getParentFile().mkdirs());

	    String value = null;

	    XMLConfiguration configuration = new XMLConfiguration();
	    configuration.setExpressionEngine(new XPathExpressionEngine());
	    configuration.setDelimiterParsingDisabled(true);
	    configuration.addProperty(" key1", PATH1);
	    configuration.setProperty(" key2", PATH2);
	    configuration.save(resourceFile);
            /* 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);
	    configuration.save(resourceFile);
	    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());
	    newConfiguration.setDelimiterParsingDisabled(true);
	    newConfiguration.load(resourceFile);

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

	} catch (Throwable e) {
	    e.printStackTrace();
	    fail(e.getLocalizedMessage());
	} finally {
	    /*
	     * Delete resource file
	     */
	    resourceFile.delete();
	}

    }
}

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (CONFIGURATION-440) setProperty in XmlConfiguration escapes backslashes

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-440?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oliver Heger resolved CONFIGURATION-440.
----------------------------------------

       Resolution: Duplicate
    Fix Version/s: 1.7

Got nor more feedback, so I assume this is actually a duplicate of CONFIGURATION-428.

> setProperty in XmlConfiguration escapes backslashes
> ---------------------------------------------------
>
>                 Key: CONFIGURATION-440
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-440
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Build
>    Affects Versions: 1.6
>         Environment: Windows 7
>            Reporter: B
>              Labels: build
>             Fix For: 1.7, 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. 
> Following test keeps failing. Don't know if there is some kind of formatting.
> 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";
>     @Test
>     public void testXmlConfiguration() throws IOException {
> 	File resourceFile = null;
> 	try {
> 	    assertNotNull(_bundleContext);
> 	    resourceFile = new File(SystemUtils.getTargetDirectory(),
> 		    XML_CONFIGURATION_PATH);
> 	    assertTrue(resourceFile.getParentFile().mkdirs());
> 	    String value = null;
> 	    XMLConfiguration configuration = new XMLConfiguration();
> 	    configuration.setExpressionEngine(new XPathExpressionEngine());
> 	    configuration.setDelimiterParsingDisabled(true);
> 	    configuration.addProperty(" key1", PATH1);
> 	    configuration.setProperty(" key2", PATH2);
> 	    configuration.save(resourceFile);
>             /* 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);
> 	    configuration.save(resourceFile);
> 	    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());
> 	    newConfiguration.setDelimiterParsingDisabled(true);
> 	    newConfiguration.load(resourceFile);
> 	    /*
> 	     * At this point, configuration will load escaped backslashes, and
> 	     * the test will fail.
> 	     */
> 	    value = newConfiguration.getString("key2");
> 	    assertEquals(value, PATH3);
> 	} catch (Throwable e) {
> 	    e.printStackTrace();
> 	    fail(e.getLocalizedMessage());
> 	} finally {
> 	    /*
> 	     * Delete resource file
> 	     */
> 	    resourceFile.delete();
> 	}
>     }
> }

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (CONFIGURATION-440) setProperty in XmlConfiguration escapes backslashes

Posted by "B (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-440?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

B updated CONFIGURATION-440:
----------------------------

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

Following test keeps failing. Don't know if there is some kind of formatting.

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";

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

	    assertNotNull(_bundleContext);
	    resourceFile = new File(SystemUtils.getTargetDirectory(),
		    XML_CONFIGURATION_PATH);
	    assertTrue(resourceFile.getParentFile().mkdirs());

	    String value = null;

	    XMLConfiguration configuration = new XMLConfiguration();
	    configuration.setExpressionEngine(new XPathExpressionEngine());
	    configuration.setDelimiterParsingDisabled(true);
	    configuration.addProperty(" key1", PATH1);
	    configuration.setProperty(" key2", PATH2);
	    configuration.save(resourceFile);
            /* 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);
	    configuration.save(resourceFile);
	    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());
	    newConfiguration.setDelimiterParsingDisabled(true);
	    newConfiguration.load(resourceFile);

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

	} catch (Throwable e) {
	    e.printStackTrace();
	    fail(e.getLocalizedMessage());
	} finally {
	    /*
	     * Delete resource file
	     */
	    resourceFile.delete();
	}

    }
}

  was:
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";

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

	    assertNotNull(_bundleContext);
	    resourceFile = new File(SystemUtils.getTargetDirectory(),
		    XML_CONFIGURATION_PATH);
	    assertTrue(resourceFile.getParentFile().mkdirs());

	    String value = null;

	    XMLConfiguration configuration = new XMLConfiguration();
	    configuration.setExpressionEngine(new XPathExpressionEngine());
	    configuration.setDelimiterParsingDisabled(true);
	    configuration.addProperty(" key1", PATH1);
	    configuration.setProperty(" key2", PATH2);
	    configuration.save(resourceFile);
            /* 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);
	    configuration.save(resourceFile);
	    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());
	    newConfiguration.setDelimiterParsingDisabled(true);
	    newConfiguration.load(resourceFile);

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

	} catch (Throwable e) {
	    e.printStackTrace();
	    fail(e.getLocalizedMessage());
	} finally {
	    /*
	     * Delete resource file
	     */
	    resourceFile.delete();
	}

    }
}


> setProperty in XmlConfiguration escapes backslashes
> ---------------------------------------------------
>
>                 Key: CONFIGURATION-440
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-440
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Build
>    Affects Versions: 1.6
>         Environment: Windows 7
>            Reporter: B
>              Labels: build
>             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. 
> Following test keeps failing. Don't know if there is some kind of formatting.
> 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";
>     @Test
>     public void testXmlConfiguration() throws IOException {
> 	File resourceFile = null;
> 	try {
> 	    assertNotNull(_bundleContext);
> 	    resourceFile = new File(SystemUtils.getTargetDirectory(),
> 		    XML_CONFIGURATION_PATH);
> 	    assertTrue(resourceFile.getParentFile().mkdirs());
> 	    String value = null;
> 	    XMLConfiguration configuration = new XMLConfiguration();
> 	    configuration.setExpressionEngine(new XPathExpressionEngine());
> 	    configuration.setDelimiterParsingDisabled(true);
> 	    configuration.addProperty(" key1", PATH1);
> 	    configuration.setProperty(" key2", PATH2);
> 	    configuration.save(resourceFile);
>             /* 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);
> 	    configuration.save(resourceFile);
> 	    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());
> 	    newConfiguration.setDelimiterParsingDisabled(true);
> 	    newConfiguration.load(resourceFile);
> 	    /*
> 	     * At this point, configuration will load escaped backslashes, and
> 	     * the test will fail.
> 	     */
> 	    value = newConfiguration.getString("key2");
> 	    assertEquals(value, PATH3);
> 	} catch (Throwable e) {
> 	    e.printStackTrace();
> 	    fail(e.getLocalizedMessage());
> 	} finally {
> 	    /*
> 	     * Delete resource file
> 	     */
> 	    resourceFile.delete();
> 	}
>     }
> }

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CONFIGURATION-440) setProperty in XmlConfiguration escapes backslashes

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-440?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13002989#comment-13002989 ] 

Oliver Heger commented on CONFIGURATION-440:
--------------------------------------------

Thanks for the report.

There has already been a similar report, recorded as CONFIGURATION-428. For this issue a fix has been applied in subversion. Could you please check whether this fix solves your problem? Unfortunately, it is necessary to checkout the recent version from subversion and to build it because the changes have not been released yet.

> setProperty in XmlConfiguration escapes backslashes
> ---------------------------------------------------
>
>                 Key: CONFIGURATION-440
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-440
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Build
>    Affects Versions: 1.6
>         Environment: Windows 7
>            Reporter: B
>              Labels: build
>             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. 
> Following test keeps failing. Don't know if there is some kind of formatting.
> 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";
>     @Test
>     public void testXmlConfiguration() throws IOException {
> 	File resourceFile = null;
> 	try {
> 	    assertNotNull(_bundleContext);
> 	    resourceFile = new File(SystemUtils.getTargetDirectory(),
> 		    XML_CONFIGURATION_PATH);
> 	    assertTrue(resourceFile.getParentFile().mkdirs());
> 	    String value = null;
> 	    XMLConfiguration configuration = new XMLConfiguration();
> 	    configuration.setExpressionEngine(new XPathExpressionEngine());
> 	    configuration.setDelimiterParsingDisabled(true);
> 	    configuration.addProperty(" key1", PATH1);
> 	    configuration.setProperty(" key2", PATH2);
> 	    configuration.save(resourceFile);
>             /* 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);
> 	    configuration.save(resourceFile);
> 	    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());
> 	    newConfiguration.setDelimiterParsingDisabled(true);
> 	    newConfiguration.load(resourceFile);
> 	    /*
> 	     * At this point, configuration will load escaped backslashes, and
> 	     * the test will fail.
> 	     */
> 	    value = newConfiguration.getString("key2");
> 	    assertEquals(value, PATH3);
> 	} catch (Throwable e) {
> 	    e.printStackTrace();
> 	    fail(e.getLocalizedMessage());
> 	} finally {
> 	    /*
> 	     * Delete resource file
> 	     */
> 	    resourceFile.delete();
> 	}
>     }
> }

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira