Skip to content

Commit 9eb095d

Browse files
committed
Merge branch '5.1.x'
2 parents d489227 + 293188c commit 9eb095d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,15 +39,17 @@ public static boolean simpleMatch(@Nullable String pattern, @Nullable String str
3939
if (pattern == null || str == null) {
4040
return false;
4141
}
42+
4243
int firstIndex = pattern.indexOf('*');
4344
if (firstIndex == -1) {
4445
return pattern.equals(str);
4546
}
47+
4648
if (firstIndex == 0) {
4749
if (pattern.length() == 1) {
4850
return true;
4951
}
50-
int nextIndex = pattern.indexOf('*', firstIndex + 1);
52+
int nextIndex = pattern.indexOf('*', 1);
5153
if (nextIndex == -1) {
5254
return str.endsWith(pattern.substring(1));
5355
}
@@ -64,6 +66,7 @@ public static boolean simpleMatch(@Nullable String pattern, @Nullable String str
6466
}
6567
return false;
6668
}
69+
6770
return (str.length() >= firstIndex &&
6871
pattern.substring(0, firstIndex).equals(str.substring(0, firstIndex)) &&
6972
simpleMatch(pattern.substring(firstIndex), str.substring(firstIndex)));

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -121,20 +121,26 @@ public String replacePlaceholders(String value, final Properties properties) {
121121
*/
122122
public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) {
123123
Assert.notNull(value, "'value' must not be null");
124-
return parseStringValue(value, placeholderResolver, new HashSet<>());
124+
return parseStringValue(value, placeholderResolver, null);
125125
}
126126

127127
protected String parseStringValue(
128-
String value, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) {
129-
130-
StringBuilder result = new StringBuilder(value);
128+
String value, PlaceholderResolver placeholderResolver, @Nullable Set<String> visitedPlaceholders) {
131129

132130
int startIndex = value.indexOf(this.placeholderPrefix);
131+
if (startIndex == -1) {
132+
return value;
133+
}
134+
135+
StringBuilder result = new StringBuilder(value);
133136
while (startIndex != -1) {
134137
int endIndex = findPlaceholderEndIndex(result, startIndex);
135138
if (endIndex != -1) {
136139
String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex);
137140
String originalPlaceholder = placeholder;
141+
if (visitedPlaceholders == null) {
142+
visitedPlaceholders = new HashSet<>(4);
143+
}
138144
if (!visitedPlaceholders.add(originalPlaceholder)) {
139145
throw new IllegalArgumentException(
140146
"Circular placeholder reference '" + originalPlaceholder + "' in property definitions");
@@ -178,7 +184,6 @@ else if (this.ignoreUnresolvablePlaceholders) {
178184
startIndex = -1;
179185
}
180186
}
181-
182187
return result.toString();
183188
}
184189

0 commit comments

Comments
 (0)