Skip to content

Commit

Permalink
Restore nested property resolution for non CharSequence types
Browse files Browse the repository at this point in the history
Closes gh-33727

Co-authored-by: Andy Wilkinson <[email protected]>
  • Loading branch information
snicoll and wilkinsona committed Oct 17, 2024
1 parent cbdfe81 commit bdf76b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ protected <T> T getProperty(String key, Class<T> targetValueType, boolean resolv
}
Object value = propertySource.getProperty(key);
if (value != null) {
if (resolveNestedPlaceholders &&
(String.class.equals(targetValueType) || CharSequence.class.equals(targetValueType)) &&
value instanceof CharSequence cs) {
value = resolveNestedPlaceholders(cs.toString());
if (resolveNestedPlaceholders) {
if (value instanceof String string) {
value = resolveNestedPlaceholders(string);
}
else if ((value instanceof CharSequence cs) && (String.class.equals(targetValueType) ||
CharSequence.class.equals(targetValueType))) {
value = resolveNestedPlaceholders(cs.toString());
}
}
logKeyFound(key, propertySource, value);
return convertValueIfNecessary(value, targetValueType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ void resolveNestedPlaceholdersIfValueIsCharSequenceAndStringBuilderIsRequested()
.hasToString("${p1}:${p2}");
}

@Test // gh-33727
void resolveNestedPlaceHolderIfValueShouldConvertToOtherTypes() {
MutablePropertySources ps = new MutablePropertySources();
ps.addFirst(new MockPropertySource().withProperty("new.enabled", "${old.enabled:true}"));
ConfigurablePropertyResolver pr = new PropertySourcesPropertyResolver(ps);
assertThat(pr.getProperty("new.enabled", Boolean.class, false)).isTrue();
}

@Test
void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
MutablePropertySources ps = new MutablePropertySources();
Expand Down

0 comments on commit bdf76b2

Please sign in to comment.