Skip to content

Commit c212255

Browse files
stsypanovjhoeller
authored andcommitted
Improve UriComponents.sanitizeSource()
1 parent 7b6e1c9 commit c212255

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-web/src/main/java/org/springframework/web/util/UriComponents.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ static String expandUriComponent(@Nullable String source, UriTemplateVariables u
276276
*/
277277
private static String sanitizeSource(String source) {
278278
int level = 0;
279-
StringBuilder sb = new StringBuilder();
279+
int lastCharIndex = 0;
280+
char[] chars = new char[source.length()];
280281
for (char c : source.toCharArray()) {
281282
if (c == '{') {
282283
level++;
@@ -287,9 +288,9 @@ private static String sanitizeSource(String source) {
287288
if (level > 1 || (level == 1 && c == '}')) {
288289
continue;
289290
}
290-
sb.append(c);
291+
chars[lastCharIndex++] = c;
291292
}
292-
return sb.toString();
293+
return new String(chars, 0, lastCharIndex);
293294
}
294295

295296
private static String getVariableName(String match) {

0 commit comments

Comments
 (0)