This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 599e6d8628 Review "Trim and escape the Out tag plugin body fallback"
599e6d8628 is described below

commit 599e6d86287ebf7d936c732470072d9aa5edbeef
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Nov 6 11:55:03 2026 +0000

    Review "Trim and escape the Out tag plugin body fallback"
    
    Optimise no body case
    
    Co-authored by: Claude / Sonnet 5.5
---
 java/org/apache/jasper/compiler/TagPluginManager.java         |  5 +++++
 .../apache/jasper/compiler/tagplugin/TagPluginContext.java    | 11 +++++++++++
 java/org/apache/jasper/tagplugins/jstl/core/Out.java          |  5 +++++
 3 files changed, 21 insertions(+)

diff --git a/java/org/apache/jasper/compiler/TagPluginManager.java 
b/java/org/apache/jasper/compiler/TagPluginManager.java
index 122462d48a..24ed0e053b 100644
--- a/java/org/apache/jasper/compiler/TagPluginManager.java
+++ b/java/org/apache/jasper/compiler/TagPluginManager.java
@@ -223,6 +223,11 @@ public class TagPluginManager {
             return node.getChildInfo().isScriptless();
         }
 
+        @Override
+        public boolean hasBody() {
+            return !node.hasEmptyBody();
+        }
+
         @Override
         public boolean isConstantAttribute(String attribute) {
             Node.JspAttribute attr = getNodeAttribute(attribute);
diff --git a/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java 
b/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java
index e17897e1f1..848775da93 100644
--- a/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java
+++ b/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java
@@ -30,6 +30,17 @@ public interface TagPluginContext {
      */
     boolean isScriptless();
 
+    /**
+     * Checks whether the current tag has a body. A tag whose only children 
are <code>jsp:attribute</code> actions, or
+     * whose <code>jsp:body</code> is empty, has no body. A body that contains 
only whitespace is still a body.
+     *
+     * @return true if the tag has a body, false if the body is empty. The 
default implementation returns true, which
+     *             is always safe for a plugin that uses the query to skip 
work that is only needed for a body.
+     */
+    default boolean hasBody() {
+        return true;
+    }
+
     /**
      * Checks whether the specified attribute is present in the current tag.
      *
diff --git a/java/org/apache/jasper/tagplugins/jstl/core/Out.java 
b/java/org/apache/jasper/tagplugins/jstl/core/Out.java
index c9bb8c09de..e7b6304790 100644
--- a/java/org/apache/jasper/tagplugins/jstl/core/Out.java
+++ b/java/org/apache/jasper/tagplugins/jstl/core/Out.java
@@ -91,6 +91,11 @@ public final class Out implements TagPlugin {
         ctxt.generateJavaSource(
                 "boolean " + strSkipBodyName + " = " + 
"org.apache.jasper.tagplugins.jstl.core.Out.output(out, " +
                         strObjectName + ", " + strValName + ", " + strDefName 
+ ", " + strEscapeXmlName + ");");
+        if (!ctxt.hasBody()) {
+            // There is no body to use as a fallback, so there is nothing to
+            // buffer. Avoid allocating a BodyContent for every null value.
+            return;
+        }
         ctxt.generateJavaSource("if(!" + strSkipBodyName + ") {");
         // Neither the value nor the default produced output. As in the
         // standard tag handler, capture the body content, then output it


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to