|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -121,20 +121,26 @@ public String replacePlaceholders(String value, final Properties properties) {
|
121 | 121 | */
|
122 | 122 | public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) {
|
123 | 123 | Assert.notNull(value, "'value' must not be null");
|
124 |
| - return parseStringValue(value, placeholderResolver, new HashSet<>()); |
| 124 | + return parseStringValue(value, placeholderResolver, null); |
125 | 125 | }
|
126 | 126 |
|
127 | 127 | 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) { |
131 | 129 |
|
132 | 130 | int startIndex = value.indexOf(this.placeholderPrefix);
|
| 131 | + if (startIndex == -1) { |
| 132 | + return value; |
| 133 | + } |
| 134 | + |
| 135 | + StringBuilder result = new StringBuilder(value); |
133 | 136 | while (startIndex != -1) {
|
134 | 137 | int endIndex = findPlaceholderEndIndex(result, startIndex);
|
135 | 138 | if (endIndex != -1) {
|
136 | 139 | String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex);
|
137 | 140 | String originalPlaceholder = placeholder;
|
| 141 | + if (visitedPlaceholders == null) { |
| 142 | + visitedPlaceholders = new HashSet<>(4); |
| 143 | + } |
138 | 144 | if (!visitedPlaceholders.add(originalPlaceholder)) {
|
139 | 145 | throw new IllegalArgumentException(
|
140 | 146 | "Circular placeholder reference '" + originalPlaceholder + "' in property definitions");
|
@@ -178,7 +184,6 @@ else if (this.ignoreUnresolvablePlaceholders) {
|
178 | 184 | startIndex = -1;
|
179 | 185 | }
|
180 | 186 | }
|
181 |
| - |
182 | 187 | return result.toString();
|
183 | 188 | }
|
184 | 189 |
|
|
0 commit comments