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

ConfigurationConverter Adding Escape Character to Delimited String

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.7
    • 2.7
    • Interpolation
    • None
    • Ubuntu 18.04

      Jdk 1.8

    Description

       

      I'm working on a project that needs to define and load some properties as delimited lists of strings. I noticed that when I went to load my properties from the configuration, the resulting string has escape characters added before each delimiter. So if my property file has the line 

      mail.to.nav=a@b.com-foo@tura.com-12@34.com

       

      then the result of looking up the property will be

      a@b.com/-foo@tura.com/-12@34.com

       

      I'm not sure whether this behaviour is intentional or a bug, but it causes problems when trying to use the 'split()' method of AbstractListDelimiterHandler. The escape character causes the delimiter to be treated as a literal, so the string does not get split into parts. Below is a test case demonstrating the behaviour I'm seeing.

       

       

      @Test
      public void testPropertyParsingWithEscape() throws IOException, ConfigurationException
      {
          File tmpOutput = File.createTempFile("test", ".properties");
          Writer out = new FileWriter(tmpOutput);
          out.write("mail.to.nav=a@b.com-foo@tura.com-12@34.com");
          out.append("\nmail.to.error=x@y.com\\-foo@tura.com");
          out.append("\nmail.to=q@r.com\\\\-foo@tura.com");
          out.close();
       
          Configurations configurations = new Configurations();
          CompositeConfiguration cc = new CompositeConfiguration();
          ListDelimiterHandler handler = new DefaultListDelimiterHandler('-');
          cc.setListDelimiterHandler(handler);
           
          cc.addConfiguration(configurations.properties(tmpOutput));
           
          Configuration config = cc;
          final Properties props = ConfigurationConverter.getProperties(config);        
              String navTo = (String) props.get("mail.to.nav");
              assertNotNull(navTo);
              String errorTo = (String) props.get("mail.to.error");
              assertNotNull(errorTo);
              String to = (String) props.get("mail.to");
              assertNotNull(to);
       
              List<String> lst1 = (List<String>) handler.split(navTo, true);
              List<String> lst2 = (List<String>) handler.split(errorTo, true);
              List<String> lst3 = (List<String>) handler.split(to, true);
              assertThat(lst1, contains(  Arrays.asList("a@b.com","foo@tura.com","12@34.com")) );
              assertThat(lst2, contains( Arrays.asList("x@y.com","foo@tura.com")) );
              assertThat(lst3, contains( Arrays.asList("q@r.com","foo@tura.com")) );
              
      }
      

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            pbtura Patrick Buchheit
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: