From 6305a69cc14f90a6e65e96362d38cab46e6c8b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=A6=D1=8B=D0=BF?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 12 May 2020 19:36:31 +0300 Subject: [PATCH] Avoid StringBuilder.append(Object) in ContentDisposition This commit avoids invoking StringBuilder.append(Object) in favor of explicit method calls to append(String) and append(char) in ContentDisposition.escapeQuotationsInFilename(String). Closes gh-25056 --- .../java/org/springframework/http/ContentDisposition.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java index c87efa771ce..f0586079289 100644 --- a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java +++ b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java @@ -39,6 +39,7 @@ import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME; * @author Sebastien Deleuze * @author Juergen Hoeller * @author Rossen Stoyanchev + * @author Sergey Tsypanov * @since 5.0 * @see RFC 6266 */ @@ -436,7 +437,11 @@ public final class ContentDisposition { boolean escaped = false; StringBuilder sb = new StringBuilder(); for (char c : filename.toCharArray()) { - sb.append((c == '"' && !escaped) ? "\\\"" : c); + if (!escaped && c == '"') { + sb.append("\\\""); + } else { + sb.append(c); + } escaped = (!escaped && c == '\\'); } // Remove backslash at the end..