[
https://issues.apache.org/jira/browse/CONFIGURATION-811?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Patrick Buchheit updated CONFIGURATION-811:
-------------------------------------------
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
*[email protected]@[[email protected]|mailto:[email protected]]*
then the result of looking up the property will be
*[email protected]/-foo@[tura.com/[email protected]|mailto:[email protected]]*
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.
{code:java}
@Test
public void testPropertyParsingWithEscape() throws IOException,
ConfigurationException
{
File tmpOutput = File.createTempFile("test", ".properties");
Writer out = new FileWriter(tmpOutput);
out.write("[email protected][email protected][email protected]");
out.append("\[email protected]\\[email protected]");
out.append("\[email protected]\\\\[email protected]");
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("[email protected]","[email protected]","[email protected]")) );
assertThat(lst2, contains( Arrays.asList("[email protected]","[email protected]"))
);
assertThat(lst3, contains( Arrays.asList("[email protected]","[email protected]"))
);
}
{code}
was:
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
*[email protected]@[[email protected]|mailto:[email protected]]*
then ** the result of looking up the property will be
*[email protected]/-foo@[tura.com/[email protected]|mailto:[email protected]]*
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.
{code:java}
@Test
public void testPropertyParsingWithEscape() throws IOException,
ConfigurationException
{
File tmpOutput = File.createTempFile("test", ".properties");
Writer out = new FileWriter(tmpOutput);
out.write("[email protected][email protected][email protected]");
out.append("\[email protected]\\[email protected]");
out.append("\[email protected]\\\\[email protected]");
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("[email protected]","[email protected]","[email protected]")) );
assertThat(lst2, contains( Arrays.asList("[email protected]","[email protected]"))
);
assertThat(lst3, contains( Arrays.asList("[email protected]","[email protected]"))
);
}
{code}
> ConfigurationConverter Adding Escape Character to Delimited String
> -------------------------------------------------------------------
>
> Key: CONFIGURATION-811
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-811
> Project: Commons Configuration
> Issue Type: Bug
> Components: Interpolation
> Affects Versions: 2.7
> Environment: Ubuntu 18.04
> Jdk 1.8
> Reporter: Patrick Buchheit
> Priority: Major
>
>
> 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
> *[email protected]@[[email protected]|mailto:[email protected]]*
>
> then the result of looking up the property will be
> *[email protected]/-foo@[tura.com/[email protected]|mailto:[email protected]]*
>
> 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.
>
>
> {code:java}
> @Test
> public void testPropertyParsingWithEscape() throws IOException,
> ConfigurationException
> {
> File tmpOutput = File.createTempFile("test", ".properties");
> Writer out = new FileWriter(tmpOutput);
> out.write("[email protected][email protected][email protected]");
> out.append("\[email protected]\\[email protected]");
> out.append("\[email protected]\\\\[email protected]");
> 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("[email protected]","[email protected]","[email protected]")) );
> assertThat(lst2, contains(
> Arrays.asList("[email protected]","[email protected]")) );
> assertThat(lst3, contains(
> Arrays.asList("[email protected]","[email protected]")) );
>
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)