Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copied config node uses unescaped key if the key contains a dot #6295

Closed
tjquinno opened this issue Feb 25, 2023 · 2 comments
Closed

Copied config node uses unescaped key if the key contains a dot #6295

tjquinno opened this issue Feb 25, 2023 · 2 comments
Assignees
Labels
4.x Version 4.x bug Something isn't working config

Comments

@tjquinno
Copy link
Member

Environment Details

  • Helidon Version: 4.x
  • Helidon SE or Helidon MP
  • JDK version:
  • OS:
  • Docker version (if applicable):

Problem Description

When a config node is copied, if the key contains a dot the copied key is not escaped so the resulting copy has the wrong key.

Steps to reproduce

Add the following test to ConfigCopyTest and run it. It fails because the copied key is not escaped when the new copy of the node is created:

   @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"));
    }
@tjquinno tjquinno added bug Something isn't working config 4.x Version 4.x labels Feb 25, 2023
@tjquinno tjquinno self-assigned this Feb 25, 2023
@danielkec
Copy link
Contributor

Same test seems to be failing in 3.x too

@tjquinno
Copy link
Member Author

Yes. I've created backport issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x bug Something isn't working config
Projects
Archived in project
Development

No branches or pull requests

2 participants