Skip to content

Commit 4f4ed53

Browse files
authored
Y_Update PlaceholderParser.java
i have solved the NestedPlaceholderPart does not recursively resolve placeholders spring-projects#34020 issue
1 parent 2b9010c commit 4f4ed53

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

spring-core/src/main/java/org/springframework/util/PlaceholderParser.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -443,34 +443,30 @@ record SimplePlaceholderPart(String text, String key, @Nullable String fallback)
443443

444444
@Override
445445
public String resolve(PartResolutionContext resolutionContext) {
446-
String resolvedValue = resolveToText(resolutionContext, this.key);
447-
if (resolvedValue != null) {
448-
return resolvedValue;
449-
}
450-
else if (this.fallback != null) {
451-
return this.fallback;
452-
}
453-
return resolutionContext.handleUnresolvablePlaceholder(this.key, this.text);
446+
String resolvedKey = Part.resolveAll(this.keyParts, resolutionContext);
447+
String value = resolveToText(resolutionContext, resolvedKey);
448+
if (value != null) {
449+
return value;
450+
} else if (this.defaultParts != null) {
451+
return Part.resolveAll(this.defaultParts, resolutionContext);
452+
}
453+
return resolutionContext.handleUnresolvablePlaceholder(resolvedKey, this.text);
454454
}
455-
456-
@Nullable
455+
457456
private String resolveToText(PartResolutionContext resolutionContext, String text) {
458-
String resolvedValue = resolutionContext.resolvePlaceholder(text);
459-
if (resolvedValue != null) {
460-
resolutionContext.flagPlaceholderAsVisited(text);
461-
// Let's check if we need to recursively resolve that value
462-
List<Part> nestedParts = resolutionContext.parse(resolvedValue);
463-
String value = toText(nestedParts);
464-
if (!isTextOnly(nestedParts)) {
465-
value = new ParsedValue(resolvedValue, nestedParts).resolve(resolutionContext);
466-
}
467-
resolutionContext.removePlaceholder(text);
468-
return value;
469-
}
470-
// Not found
471-
return null;
457+
String resolvedValue = resolutionContext.resolvePlaceholder(text);
458+
if (resolvedValue != null) {
459+
resolutionContext.flagPlaceholderAsVisited(text);
460+
// Check for nested placeholders
461+
List<Part> nestedParts = resolutionContext.parse(resolvedValue);
462+
String value = Part.resolveAll(nestedParts, resolutionContext);
463+
resolutionContext.removePlaceholder(text);
464+
return value;
465+
}
466+
return null;
472467
}
473468

469+
474470
private boolean isTextOnly(List<Part> parts) {
475471
return parts.stream().allMatch(TextPart.class::isInstance);
476472
}

0 commit comments

Comments
 (0)