Merge pull request #32876 from quaff
* pr/32876: Polish "Extend nested placeholders resolution to any CharSequence" Extend nested placeholders resolution to any CharSequence Closes gh-32876
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -84,8 +84,8 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
|
||||
}
|
||||
Object value = propertySource.getProperty(key);
|
||||
if (value != null) {
|
||||
if (resolveNestedPlaceholders && value instanceof String string) {
|
||||
value = resolveNestedPlaceholders(string);
|
||||
if (resolveNestedPlaceholders && value instanceof CharSequence cs) {
|
||||
value = resolveNestedPlaceholders(cs.toString());
|
||||
}
|
||||
logKeyFound(key, propertySource, value);
|
||||
return convertValueIfNecessary(value, targetValueType);
|
||||
|
||||
@@ -300,6 +300,19 @@ class PropertySourcesPropertyResolverTests {
|
||||
.withMessageContaining("Circular");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNestedPlaceholdersIfValueIsCharSequence() {
|
||||
MutablePropertySources ps = new MutablePropertySources();
|
||||
ps.addFirst(new MockPropertySource()
|
||||
.withProperty("p1", "v1")
|
||||
.withProperty("p2", "v2")
|
||||
.withProperty("p3", new StringBuilder("${p1}:${p2}")));
|
||||
ConfigurablePropertyResolver pr = new PropertySourcesPropertyResolver(ps);
|
||||
assertThat(pr.getProperty("p1")).isEqualTo("v1");
|
||||
assertThat(pr.getProperty("p2")).isEqualTo("v2");
|
||||
assertThat(pr.getProperty("p3")).isEqualTo("v1:v2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
|
||||
MutablePropertySources ps = new MutablePropertySources();
|
||||
|
||||
Reference in New Issue
Block a user