Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 5002e40

Browse files
committed
Catering for variable interpolation like:
p = a${b}${c}d
1 parent c980ff4 commit 5002e40

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main/java/com/morgan/design/properties/internal/ReadablePropertySourcesPlaceholderConfigurer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ public void startWatching() {
9494
}
9595

9696
public Object resolveProperty(final Object property) {
97-
final Object resolvedPropertyValue = this.properties.get(this.propertyResolver.resolveProperty(property));
98-
if (this.propertyResolver.requiresFurtherResoltuion(resolvedPropertyValue)) {
99-
return resolveProperty(resolvedPropertyValue);
97+
Object resolvedPropertyValue = this.properties.get(this.propertyResolver.resolveProperty(property));
98+
while (this.propertyResolver.requiresFurtherResoltuion(resolvedPropertyValue)) {
99+
String resolvedValueStr = resolvedPropertyValue.toString();
100+
int startingIndex = resolvedValueStr.indexOf("${");
101+
int endingIndex = resolvedValueStr.indexOf("}", startingIndex) + 1;
102+
String toResolve = resolvedValueStr.substring(startingIndex, endingIndex);
103+
String resolved = resolveProperty(toResolve).toString();
104+
resolvedPropertyValue = resolvedValueStr.substring(0, startingIndex) + resolved + resolvedValueStr.substring(endingIndex);
100105
}
101106
return resolvedPropertyValue;
102107
}

src/main/java/com/morgan/design/properties/resolver/SubstitutingPropertyResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public boolean requiresFurtherResoltuion(final Object property) {
5151
*/
5252
private boolean propertyRequiresSubstitution(final String property) {
5353
if (null != property) {
54-
return property.startsWith("${") && property.endsWith("}");
54+
return property.contains("${") && property.contains("}") && property.indexOf("${") < property.indexOf("}");
5555
}
5656
return false;
5757
}

0 commit comments

Comments
 (0)