Skip to content

Commit

Permalink
* Fix SeConfig.asMap to not truncate keys
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-grecourt committed Aug 29, 2023
1 parent 97de830 commit f30898a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -260,8 +260,12 @@ public ConfigValue<Map<String, String>> asMap() throws MissingValueException {
continue;
}
if (propertyName.startsWith(stringKey + ".")) {
String noPrefix = propertyName.substring(stringPrefix.length() + 1);

String noPrefix;
if (stringPrefix.isEmpty()) {
noPrefix = propertyName;
} else {
noPrefix = propertyName.substring(stringPrefix.length() + 1);
}
children.put(noPrefix, delegate.getValue(propertyName, String.class));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -180,6 +180,23 @@ public void testMpToHelidonConfigMappingServicesNotDisabled() {
assertThat(TestMapperProvider.getCreationCount(), is(1));
}

@Test
public void testSeConfigAsMap() {
Config mpConfig = ConfigProviderResolver.instance().getBuilder()
.withSources(MpConfigSources.create(Map.of(
"client.headers.0.name", "foo"
)))
.build();
io.helidon.config.Config seConfig = MpConfig.toHelidonConfig(mpConfig);
Map<String, String> map;

map = seConfig.get("client").asMap().orElse(Map.of());
assertThat(map.get("client.headers.0.name"), is("foo"));

map = seConfig.get("client").detach().asMap().orElse(Map.of());
assertThat(map.get("headers.0.name"), is("foo"));
}

// Github issue #2206
@Test
void testFailing() {
Expand Down

0 comments on commit f30898a

Please sign in to comment.