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

setProperty in XmlConfiguration escapes backslashes

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 1.6
    • Fix Version/s: 1.7, 2.0
    • Component/s: Build
    • Labels:
    • Environment:

      Windows 7

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

      }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bjevtic B
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: