You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/01/12 01:10:46 UTC

svn commit: r898126 - /tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java

Author: markt
Date: Tue Jan 12 00:10:46 2010
New Revision: 898126

URL: http://svn.apache.org/viewvc?rev=898126&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47977
Using a body with tags specified to have empty body content should cause an error

Modified:
    tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java

Modified: tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java?rev=898126&r1=898125&r2=898126&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java Tue Jan 12 00:10:46 2010
@@ -109,6 +109,8 @@
     // 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 @@
         AttributesImpl nonTaglibAttrs = null;
         AttributesImpl nonTaglibXmlnsAttrs = null;
 
+        checkEmptyBody();
+
         processChars();
 
         checkPrefixes(uri, qName, attrs);
@@ -426,9 +430,10 @@
                 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 @@
      * @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 @@
     public void endElement(String uri, String localName, String qName)
         throws SAXException {
 
+        if (tagEmptyBody != null) {
+            tagEmptyBody = null;
+        }
+        
         processChars();
 
         if (directivesOnly &&
@@ -703,6 +715,7 @@
      */
     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 @@
         return "";
     }
 
+    private void checkEmptyBody() throws SAXException {
+        if (tagEmptyBody != null) {
+            throw new SAXParseException(Localizer.getMessage(
+                    "jasper.error.emptybodycontent.nonempty",
+                    tagEmptyBody.qName), locator);
+        }
+    }
     /*
      * Gets SAXParser.
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r898126 - /tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java

Posted by Mark Thomas <ma...@apache.org>.
On 12/01/2010 01:45, Konstantin Kolinko wrote:
> 2010/1/12  <ma...@apache.org>:
>> Author: markt
>> Date: Tue Jan 12 00:10:46 2010
>> New Revision: 898126
>>
>> URL: http://svn.apache.org/viewvc?rev=898126&view=rev
>> Log:
>> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47977
>> Using a body with tags specified to have empty body content should cause an error
>>
>> Modified:
>>    tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java
>>
> 
>> @@ -426,9 +430,10 @@
>>                 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;
>>                 }
>>             }
>>         }
> 
> Why there is equalsIgnoreCase() in the old code? Did the specification
> ever allow wrong-cased values there?  If yes, then maybe the added
> clause should also use equalsIgnoreCase.

The spec consistently uses the same case for all possible values of
<body-content>. Since XML is case sensitive one could argue it should
always be "empty" in this case. That said, I think being lenient here is
the pragmatic thing to do so I'll make the check case-insensitive.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r898126 - /tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/1/12  <ma...@apache.org>:
> Author: markt
> Date: Tue Jan 12 00:10:46 2010
> New Revision: 898126
>
> URL: http://svn.apache.org/viewvc?rev=898126&view=rev
> Log:
> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47977
> Using a body with tags specified to have empty body content should cause an error
>
> Modified:
>    tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java
>

> @@ -426,9 +430,10 @@
>                 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;
>                 }
>             }
>         }

Why there is equalsIgnoreCase() in the old code? Did the specification
ever allow wrong-cased values there?  If yes, then maybe the added
clause should also use equalsIgnoreCase.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org