Skip to content

Commit

Permalink
Correctly match Env names when mapping contains empty names (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Feb 27, 2025
1 parent fd12b46 commit b0383e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void matchPropertiesWithEnv(final MappingBuilder mappings) {
* properties do not match.
*/
private static List<Integer> indexOfDashes(final String mappedProperty, final String envProperty) {
if (mappedProperty.length() > envProperty.length()) {
if (mappedProperty.isEmpty() || mappedProperty.length() > envProperty.length()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static java.util.stream.StreamSupport.stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -363,6 +364,27 @@ interface Nested {
}
}

@Test
void dashedEnvNamesWithEmpty() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withSources(new EnvConfigSource(Map.of("DASHED_IGNORED_ERRORS_0_", "error0"), 300))
.withMapping(DashedEnvNamesWithEmpty.class)
.build();

DashedEnvNamesWithEmpty mapping = config.getConfigMapping(DashedEnvNamesWithEmpty.class);

assertTrue(mapping.ignoredErrors().isPresent());
mapping.ignoredErrors().ifPresent(ignoredErrors -> assertIterableEquals(List.of("error0"), ignoredErrors));
}

@ConfigMapping(prefix = "dashed")
interface DashedEnvNamesWithEmpty {
@WithParentName
Optional<Boolean> enable();

Optional<List<String>> ignoredErrors();
}

@Test
void ignoreUnmappedWithMappingIgnore() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
Expand Down

0 comments on commit b0383e1

Please sign in to comment.