You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Johan Maasing (JIRA)" <ji...@apache.org> on 2012/11/20 16:44:58 UTC

[jira] [Created] (CONFIGURATION-516) PropertiesConfiguration.save escapes double qoutes " unecessary

Johan Maasing created CONFIGURATION-516:
-------------------------------------------

             Summary: PropertiesConfiguration.save escapes double qoutes " unecessary
                 Key: CONFIGURATION-516
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-516
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 1.9
            Reporter: Johan Maasing
            Priority: Minor


Add a property with a value containing " (double quote character) and saving it back to file will result in the value being modified and unecessary escaping of the quote character.

The reason is that PropertiesConfig calls into the StringEscapeUtils#escapeJavaStyleString that escapes quotes. This is not correct for propertiesfiles. http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader) says "Escapes are not necessary for single and double quotes"

Here is a test case:

@Test
public void shouldNotEscapeQuotesInTheResult() throws ConfigurationException, IOException {
    final String value = "-Djava.io.tmpdir=\"${TEST_TEMP_DIR}\"";
    
    PropertiesConfiguration testConfig = new PropertiesConfiguration();
    testConfig.addProperty("testKey1", value);
    File testFile = new File(tempTestDir.getPath() + "\\prop-with-quotes.properties");
    testConfig.save(testFile) ;
    
    String testFileContent = FileUtils.readFileToString(testFile);
    
    Assert.assertTrue(testFileContent.contains(value));
}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CONFIGURATION-516) PropertiesConfiguration.save escapes double qoutes " unecessary

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

Oliver Heger commented on CONFIGURATION-516:
--------------------------------------------

If the escaping behavior is incorrect, we should fix it rather than only providing users a way to work around the problem. Any chance that you can submit a patch?
                
> PropertiesConfiguration.save escapes double qoutes " unecessary
> ---------------------------------------------------------------
>
>                 Key: CONFIGURATION-516
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-516
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.9
>            Reporter: Johan Maasing
>            Priority: Minor
>
> Add a property with a value containing " (double quote character) and saving it back to file will result in the value being modified and unecessary escaping of the quote character.
> The reason is that PropertiesConfig calls into the StringEscapeUtils#escapeJavaStyleString that escapes quotes. This is not correct for propertiesfiles. http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader) says "Escapes are not necessary for single and double quotes"
> Here is a test case:
> @Test
> public void shouldNotEscapeQuotesInTheResult() throws ConfigurationException, IOException {
>     final String value = "-Djava.io.tmpdir=\"${TEST_TEMP_DIR}\"";
>     
>     PropertiesConfiguration testConfig = new PropertiesConfiguration();
>     testConfig.addProperty("testKey1", value);
>     File testFile = new File(tempTestDir.getPath() + "\\prop-with-quotes.properties");
>     testConfig.save(testFile) ;
>     
>     String testFileContent = FileUtils.readFileToString(testFile);
>     
>     Assert.assertTrue(testFileContent.contains(value));
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira