This is an automated email from the ASF dual-hosted git repository. theigl pushed a commit to branch wicket-9.x in repository https://gitbox.apache.org/repos/asf/wicket.git
commit bbc67b9b1cb12cdf472a490d265c4666f4c8e290 Author: Thomas Heigl <[email protected]> AuthorDate: Tue Apr 11 17:10:07 2023 +0200 WICKET-7042 Correctly size `StringResponse` when writing combined scripts (#573) (cherry picked from commit 4798a92784fae8ea22b907cdf4d915c00eb4522c) --- .../java/org/apache/wicket/page/PartialPageUpdate.java | 8 +++++++- .../java/org/apache/wicket/response/StringResponse.java | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java b/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java index f5cef0236b..5b179f1c88 100644 --- a/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java +++ b/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java @@ -71,6 +71,12 @@ public abstract class PartialPageUpdate { private static final Logger LOG = LoggerFactory.getLogger(PartialPageUpdate.class); + /** + * Length of the script block that combined scripts are wrapped in. This includes the script tag, + * CDATA and if CSP is enabled also the nonce. + */ + private static final int SCRIPT_BLOCK_LENGTH = 100; + /** * A list of scripts (JavaScript) which should be executed on the client side before the * components' replacement @@ -265,7 +271,7 @@ public abstract class PartialPageUpdate combinedScript.append("(function(){").append(script).append("})();"); } - StringResponse stringResponse = new StringResponse(); + StringResponse stringResponse = new StringResponse(combinedScript.length() + SCRIPT_BLOCK_LENGTH); IHeaderResponse decoratedHeaderResponse = Application.get().decorateHeaderResponse(new HeaderResponse() { @Override diff --git a/wicket-core/src/main/java/org/apache/wicket/response/StringResponse.java b/wicket-core/src/main/java/org/apache/wicket/response/StringResponse.java index 1f0ffddd62..dd1cf2b130 100644 --- a/wicket-core/src/main/java/org/apache/wicket/response/StringResponse.java +++ b/wicket-core/src/main/java/org/apache/wicket/response/StringResponse.java @@ -30,6 +30,8 @@ import org.apache.wicket.util.string.AppendingStringBuffer; public class StringResponse extends Response { + private static final int DEFAULT_INITIAL_CAPACITY = 128; + /** StringWriter to write to */ protected final AppendingStringBuffer out; @@ -38,7 +40,18 @@ public class StringResponse extends Response */ public StringResponse() { - out = new AppendingStringBuffer(128); + this(DEFAULT_INITIAL_CAPACITY); + } + + /** + * Constructor + * + * @param initialCapacity + * the initial capacity of the internal buffer + */ + public StringResponse(int initialCapacity) + { + out = new AppendingStringBuffer(initialCapacity); } /**
