Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-516

PropertiesConfiguration.save escapes double qoutes " unecessary

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None

      Description

      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));
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                oheger Oliver Heger
                Reporter:
                jmaasing Johan Maasing
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: