mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-05-04 05:17:15 +01:00
Restore nested property resolution for non CharSequence types
Closes gh-33727 Co-authored-by: Andy Wilkinson <andy.wilkinson@broadcom.com>
This commit is contained in:
Vendored
+8
-4
@@ -84,10 +84,14 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
|
|||||||
}
|
}
|
||||||
Object value = propertySource.getProperty(key);
|
Object value = propertySource.getProperty(key);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (resolveNestedPlaceholders &&
|
if (resolveNestedPlaceholders) {
|
||||||
(String.class.equals(targetValueType) || CharSequence.class.equals(targetValueType)) &&
|
if (value instanceof String string) {
|
||||||
value instanceof CharSequence cs) {
|
value = resolveNestedPlaceholders(string);
|
||||||
value = resolveNestedPlaceholders(cs.toString());
|
}
|
||||||
|
else if ((value instanceof CharSequence cs) && (String.class.equals(targetValueType) ||
|
||||||
|
CharSequence.class.equals(targetValueType))) {
|
||||||
|
value = resolveNestedPlaceholders(cs.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logKeyFound(key, propertySource, value);
|
logKeyFound(key, propertySource, value);
|
||||||
return convertValueIfNecessary(value, targetValueType);
|
return convertValueIfNecessary(value, targetValueType);
|
||||||
|
|||||||
Vendored
+8
@@ -325,6 +325,14 @@ class PropertySourcesPropertyResolverTests {
|
|||||||
.hasToString("${p1}:${p2}");
|
.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
|
@Test
|
||||||
void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
|
void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
|
||||||
MutablePropertySources ps = new MutablePropertySources();
|
MutablePropertySources ps = new MutablePropertySources();
|
||||||
|
|||||||
Reference in New Issue
Block a user