You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Kin-Man Chung <Ki...@Eng.Sun.COM> on 2001/09/12 21:00:49 UTC

[PATH] XML fragments in jsp handled incorrectly

This patch fixes #3350.  In a JSP document, the tags in a XML fragment are
always generated before the characters.  The current fix preserves their
orders.

misto% runsocks cvs diff -u ParserXJspSaxHandler.java
Index: ParserXJspSaxHandler.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/P
arserXJspSaxHandler.java,v
retrieving revision 1.13
diff -u -r1.13 ParserXJspSaxHandler.java
--- ParserXJspSaxHandler.java   2001/04/27 18:09:31     1.13
+++ ParserXJspSaxHandler.java   2001/09/12 18:33:59
@@ -233,8 +233,9 @@
 
         // If previous node is a custom tag, call its
         // begin tag handler
-        if (!name.equals("jsp:root")) {
-            Node prevNode = (Node)stack.peek();
+        Node prevNode = null;
+       if (!stack.empty()) {
+           prevNode = (Node)stack.peek();
             if (prevNode instanceof NodeTag) {
                 try {
                     processCustomTagBeginDoIt((NodeTag) prevNode, true);
@@ -273,6 +274,16 @@
                }
                if (!isCustomTag) {
                    // uninterpreted tag
+                   // If the parent tag is also uninterpreted, then the
+                   // characters have to be flushed, to preserve the order
+                   // of the tags and charaters that may appear in a XML
+                   // fragment, such as <a>xyz<b></b></a>
+                   if (prevNode != null && prevNode.isUninterpretedTag() &&
+                                               prevNode.getText() != null) {
+                       jspHandler.handleCharData(prevNode.start, start,
+                                                       prevNode.getText());
+                       prevNode.clearText();
+                   }
                    node.setUninterpreted(true);
                    jspHandler.handleUninterpretedTagBegin(node.start, 
                             node.start, node.rawName, node.attrs);
@@ -646,6 +657,10 @@
            ? null
            : text.toString().toCharArray();
         }
+
+       void clearText() {
+           text = null;
+       }
 
        boolean isRoot() {
            return isRoot;