diff --git a/config/config/src/main/java/io/helidon/config/ObjectNodeImpl.java b/config/config/src/main/java/io/helidon/config/ObjectNodeImpl.java index ba245e01ecd..20108d9fdc3 100644 --- a/config/config/src/main/java/io/helidon/config/ObjectNodeImpl.java +++ b/config/config/src/main/java/io/helidon/config/ObjectNodeImpl.java @@ -116,19 +116,20 @@ public MergeableNode merge(MergeableNode node) { private static void addObjectNode(Builder parentBuilder, Config parent) { parent.asNodeList().ifPresent(it -> { for (Config child : it) { + String escapedName = Config.Key.escapeName(child.name()); switch (child.type()) { case OBJECT -> { Builder childBuilder = ObjectNode.builder(); addObjectNode(childBuilder, child); - parentBuilder.addObject(child.name(), childBuilder.build()); + parentBuilder.addObject(escapedName, childBuilder.build()); } case LIST -> { ListNode.Builder childBuilder = ListNode.builder(); addListNode(childBuilder, child); - parentBuilder.addList(child.name(), childBuilder.build()); + parentBuilder.addList(escapedName, childBuilder.build()); } case VALUE -> { - parentBuilder.addValue(child.name(), child.asString().get()); + parentBuilder.addValue(escapedName, child.asString().get()); } default -> { // do nothing diff --git a/config/config/src/test/java/io/helidon/config/ConfigCopyTest.java b/config/config/src/test/java/io/helidon/config/ConfigCopyTest.java index 6ae20079b28..9f4099638aa 100644 --- a/config/config/src/test/java/io/helidon/config/ConfigCopyTest.java +++ b/config/config/src/test/java/io/helidon/config/ConfigCopyTest.java @@ -72,4 +72,40 @@ void testCopyWithArray() { assertThat(copy.get("object.second").asString(), is(ConfigValues.simpleValue("secondValue"))); assertThat(copy.get("aaa.0").asString(), is(ConfigValues.simpleValue("bbb"))); } + + @Test + void testDottedKey() { + var withDottedName = ConfigNode.ObjectNode.builder() + .addValue(Config.Key.escapeName("first.one"), "firstValue") + .addValue("second", "secondValue") + .build(); + + var rootNode = ConfigNode.ObjectNode.builder() + .addObject("object", withDottedName) + .build(); + + var originalConfig = Config.builder() + .disableSystemPropertiesSource() + .disableEnvironmentVariablesSource() + .addSource(io.helidon.config.ConfigSources.create(rootNode)) + .build(); + + assertThat("Dotted name entry in original", + originalConfig.get("object." + Config.Key.escapeName("first.one")).asString().get(), + is("firstValue")); + + var copyConfig = Config.builder() + .disableSystemPropertiesSource() + .disableEnvironmentVariablesSource() + .addSource(ConfigSources.create(originalConfig)) + .build(); + + var firstOneConfigValue = copyConfig.get("object." + Config.Key.escapeName("first.one")).asString(); + assertThat("Dotted name key in copy is present", + firstOneConfigValue.isPresent(), + is(true)); + assertThat("Dotted name value in copy", + firstOneConfigValue.get(), + is("firstValue")); + } }