Skip to content

Commit

Permalink
Guard against empty property names (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Jan 30, 2023
1 parent ac93c63 commit 7cc306e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorConte
Iterator<String> names = context.iterateNames();
while (names.hasNext()) {
String name = names.next();
if (name.charAt(0) == '%') {
if (name.length() > 0 && name.charAt(0) == '%') {
NameIterator ni = new NameIterator(name);
String profileSegment = ni.getNextSegment();
List<String> profiles = convertProfile(profileSegment.substring(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.smallrye.config.Converters.STRING_CONVERTER;
import static io.smallrye.config.KeyValuesConfigSource.config;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.StreamSupport.stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -370,7 +371,7 @@ void quotedKeysInEnv() {

SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultInterceptors()
.withSources(new EnvConfigSource(Collections.singletonMap("ENV__QUOTED_KEY__VALUE", "env"), 300))
.withSources(new EnvConfigSource(singletonMap("ENV__QUOTED_KEY__VALUE", "env"), 300))
.withSources(new KeyMapBackedConfigSource("key-map", 100, keyMap))
.build();

Expand All @@ -379,4 +380,14 @@ void quotedKeysInEnv() {
ConfigSource keymap = config.getConfigSource("key-map").get();
assertEquals("key-map", keymap.getValue("env.\"quoted-key\".value"));
}

@Test
void emptyPropertyNames() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultInterceptors()
.withSources(new EnvConfigSource(singletonMap("", "value"), 300))
.build();

assertEquals("value", config.getRawValue(""));
}
}

0 comments on commit 7cc306e

Please sign in to comment.