struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gvanma...@apache.org
Subject svn commit: r267474 - in /struts/shale/trunk/clay-plugin/src: java/org/apache/shale/clay/parser/Parser.java test/org/apache/shale/clay/parser/ParserTestCase.java
Date Sat, 03 Sep 2005 15:43:13 GMT
Author: gvanmatre
Date: Sat Sep  3 08:42:54 2005
New Revision: 267474

URL: http://svn.apache.org/viewcvs?rev=267474&view=rev
Log:
Bug#:  35839 [shale] Clay processes components inside HTML comments

Modified:
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java
    struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java?rev=267474&r1=267473&r2=267474&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java Sat Sep
 3 08:42:54 2005
@@ -457,8 +457,7 @@
         new Rule('-', true, 3, true),
         new Rule('>', false, -1, true),
         new Rule('-', false, -2, true),
-        new Rule('-', false, -3, true),
-        new Rule(' ', false, -4, true)};
+        new Rule('-', false, -3, true)};
     
     /**
      * <p>Declare an array of {@link Rule}s that validate a begin comment {@link Token}.</p>
@@ -473,8 +472,7 @@
      */    
     public static Rule[] END_COMMENT_TAG_RULES = {new Rule('>', false, -1, true),
         new Rule('-', false, -2, true),
-        new Rule('-', false, -3, true),
-        new Rule(' ', false, -4, true)};
+        new Rule('-', false, -3, true)};
     
     /**
      * <p>Declare an array of {@link Rule}s that validate document type {@link Token}.</p>
@@ -517,6 +515,9 @@
         
         nextShape: for (int i = 0; i < NODE_SHAPES.length; i++) {
             
+            int maxBeginOffset = 0;
+            int minEndOffset = Integer.MAX_VALUE;
+            
             Shape shape = NODE_SHAPES[i];
             
             Rule[] rules = shape.getRules();
@@ -525,6 +526,12 @@
                 // use the begin or end token offset 
                 int n = (rules[j].isBegin ? token.getBeginOffset() : token.getEndOffset())
+ rules[j].getOffset();
                 
+                if (rules[j].isBegin)
+                   maxBeginOffset = Math.max(n, maxBeginOffset);    
+                else
+                   minEndOffset = Math.min(n, minEndOffset);
+                    
+                
                 // if out of document range, look for the next shape
                 if (n > token.getDocument().length() || n < 0) 
                     continue nextShape;
@@ -539,6 +546,10 @@
                 if (!match) 
                     continue nextShape;    
             }
+            
+            //make sure the compared token delimiters don't overlap <!-->
+            if (minEndOffset <= maxBeginOffset)
+                continue nextShape;
             
             node.setStart(shape.isStart());
             node.setEnd(shape.isEnd());

Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java?rev=267474&r1=267473&r2=267474&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java
(original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java
Sat Sep  3 08:42:54 2005
@@ -55,13 +55,12 @@
 
         doc1.append("<p><!-- self contained comment -->").append(
                 "<!--<input type=text size=10 maxsize=10 id=username>").append(
-                "<input type=text size=10 maxsize=10 id=password> -->").append(
-                "</p>").append("<!--This is a test.  Just a test -->").append(
-                "<!--<p>Testing <b>123</b></p> -->" +
-                "<!---> -->");
+                "<input type=text size=10 maxsize=10 id=password>-->").append(
+                "</p>").append("<!--This is a test.  Just a test-->").append(
+                "<!--<p>Testing <b>123</b></p> -->");
 
         List nodes1 = p.parse(doc1);
-        assertTrue("Has 4 root nodes", nodes1.size() == 4);
+        assertTrue("Has 3 root nodes", nodes1.size() == 3);
 
         Node node = (Node) nodes1.get(0);
         assertTrue("first paragraph has 2 node", node.getChildren().size() == 2);
@@ -74,10 +73,6 @@
         assertTrue("third comment has 7 child nodes", node.getChildren()
                 .size() == 7);
 
-        node = (Node) nodes1.get(3);
-        assertTrue("forth comment has 1 child node", node.getChildren()
-                .size() == 1);
-
         
         // truncate the buffer
         doc1.setLength(0);
@@ -96,6 +91,37 @@
         node = (Node) node.getChildren().get(0);
         assertTrue("comment has 5 child nodes", node.getChildren().size() == 5);
 
+        // truncate the buffer
+        doc1.setLength(0);
+        doc1.append("<!--A Comment-->");
+        
+        nodes1 = p.parse(doc1);
+        assertTrue("one root node", nodes1.size() == 1);
+        
+        node = (Node) nodes1.get(0);
+        assertTrue("node is a valid comment", node.isComment());
+
+        // truncate the buffer
+        doc1.setLength(0);
+        doc1.append("<!-->-->");
+        
+        nodes1 = p.parse(doc1);
+        assertTrue("one root node", nodes1.size() == 1);
+        
+        node = (Node) nodes1.get(0);
+        assertTrue("node is a valid comment", node.isComment());
+
+        // truncate the buffer
+        doc1.setLength(0);
+        doc1.append("<!--<-->");
+        
+        nodes1 = p.parse(doc1);
+        assertTrue("one root node", nodes1.size() == 1);
+        
+        node = (Node) nodes1.get(0);
+        assertTrue("node is a valid comment", node.isComment());
+        
+        
     }
 
     /**



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


Mime
View raw message