Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47977
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 12 Jan 2010 00:10:46 +0000 (00:10 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 12 Jan 2010 00:10:46 +0000 (00:10 +0000)
Using a body with tags specified to have empty body content should cause an error

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@898126 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/JspDocumentParser.java

index c2dd6fb..d07016c 100644 (file)
@@ -109,6 +109,8 @@ class JspDocumentParser
     // Flag set to delay incrementing tagDependentNesting until jsp:body
     // is first encountered
     private boolean tagDependentPending = false;
+    // Tag being parsed that should have an empty body 
+    private Node tagEmptyBody = null;
 
     /*
      * Constructor
@@ -269,6 +271,8 @@ class JspDocumentParser
         AttributesImpl nonTaglibAttrs = null;
         AttributesImpl nonTaglibXmlnsAttrs = null;
 
+        checkEmptyBody();
+
         processChars();
 
         checkPrefixes(uri, qName, attrs);
@@ -426,9 +430,10 @@ class JspDocumentParser
                 if (scriptlessBodyNode == null
                         && bodyType.equalsIgnoreCase(TagInfo.BODY_CONTENT_SCRIPTLESS)) {
                     scriptlessBodyNode = node;
-                }
-                else if (TagInfo.BODY_CONTENT_TAG_DEPENDENT.equalsIgnoreCase(bodyType)) {
+                } else if (TagInfo.BODY_CONTENT_TAG_DEPENDENT.equalsIgnoreCase(bodyType)) {
                     tagDependentPending = true;
+                } else if (TagInfo.BODY_CONTENT_EMPTY.equals(bodyType)) {
+                    tagEmptyBody = node;
                 }
             }
         }
@@ -453,7 +458,10 @@ class JspDocumentParser
      * @throws SAXException
      */
     @Override
-    public void characters(char[] buf, int offset, int len) {
+    public void characters(char[] buf, int offset, int len)
+    throws SAXException {
+
+        checkEmptyBody();
 
         if (charBuffer == null) {
             charBuffer = new StringBuilder();
@@ -613,6 +621,10 @@ class JspDocumentParser
     public void endElement(String uri, String localName, String qName)
         throws SAXException {
 
+        if (tagEmptyBody != null) {
+            tagEmptyBody = null;
+        }
+        
         processChars();
 
         if (directivesOnly &&
@@ -703,6 +715,7 @@ class JspDocumentParser
      */
     public void startCDATA() throws SAXException {
 
+        checkEmptyBody();
         processChars();  // Flush char buffer and remove white spaces
         startMark = new Mark(ctxt, path, locator.getLineNumber(),
                              locator.getColumnNumber());
@@ -1388,6 +1401,13 @@ class JspDocumentParser
         return "";
     }
 
+    private void checkEmptyBody() throws SAXException {
+        if (tagEmptyBody != null) {
+            throw new SAXParseException(Localizer.getMessage(
+                    "jasper.error.emptybodycontent.nonempty",
+                    tagEmptyBody.qName), locator);
+        }
+    }
     /*
      * Gets SAXParser.
      *