[
https://issues.apache.org/jira/browse/CONFIGURATION-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16301322#comment-16301322
]
Bruno P. Kinoshita commented on CONFIGURATION-684:
--------------------------------------------------
Hi Fabien,
I believe the YAML parsing is handled by SnakeYAML. I confirmed I can use your
`file.yml` with SnakeYAML with no issues.
Actually, debugging your example (thank you a lot for including code sample) it
looks like the issue happens here
https://github.com/apache/commons-configuration/blob/a56ce4f20db01c3de9faabc5ee10db19113e83cd/src/main/java/org/apache/commons/configuration2/tree/DefaultConfigurationKey.java#L530
When we enter that method, the value of the `key` argument is still
`some.key.with.dots`. But the default list of symbols to be escaped has a `.`
(dot). So it gets escaped by a `..` (two dots).
I could not find any note about it in the [2.x
documentation|http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Special_Characters_and_Escaping],
but the [1.x
documentation|https://commons.apache.org/proper/commons-configuration/userguide_v1.10/howto_xml.html]
contains some useful information.
{quote}
# From the Escaping special characters section
Per default the dot character is used as delimiter by most configuration
classes (we will learn how to change this for hierarchical configurations in a
later section). In some configuration formats however, dots can be contained in
the names of properties. For instance, in XML the dot is a legal character that
can occur in any tag. The same is true for the names of properties in windows
ini files
{quote}
I think it is sensible to use this default behaviour for most configuration
types, and it is good to have that documented. However, I think it is possible
to have a configuration key for YAML, that allows keys to use dot without
escaping it.
So IMO we leave the ticket open until someone can work on a new configuration
key. How does that sound Fabien?
Cheers
Bruno
> YAMLConfiguration keys with double dots
> ---------------------------------------
>
> Key: CONFIGURATION-684
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-684
> Project: Commons Configuration
> Issue Type: Bug
> Reporter: Fabien Renaud
>
> h2. Issue
> Loading a YAML configuration with dotted keys causes dots to be duplicated in
> the keys of the YAMLConfiguration object.
> h2. Repro
> 100% repro:
> file.yml:
> {code}some.key.with.dots: 123{code}
> {code}
> package foo;
> import org.apache.commons.configuration2.YAMLConfiguration;
> import
> org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
> import org.apache.commons.configuration2.builder.fluent.Parameters;
> import org.apache.commons.configuration2.ex.ConfigurationException;
> public class App {
> public static void main(String[] args) throws ConfigurationException {
> Parameters params = new Parameters();
> FileBasedConfigurationBuilder<YAMLConfiguration> builder1 =
> new FileBasedConfigurationBuilder<>(YAMLConfiguration.class)
>
> .configure(params.fileBased().setFileName("file.yml"));
>
> YAMLConfiguration conf = builder1.getConfiguration();
> conf.getKeys().forEachRemaining(System.out::println);
> System.out.println("---");
> YAMLConfiguration yaml = new YAMLConfiguration();
> yaml.read(new
> InputStreamReader(ClassLoader.getSystemResourceAsStream("file.yml")));
> yaml.getKeys().forEachRemaining(System.out::println);
> }
> }
> {code}
> prints
> {code}some..key..with..dots
> ---
> some..key..with..dots
> {code}
> That is a serious bug for a configuration system. The issue may easily go
> untested for some keys and only reveal itself on production.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)