You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Oliver Heger (JIRA)" <ji...@apache.org> on 2011/03/05 17:08:46 UTC

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

    [ 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