Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Code Review use-right-element-stack-18-Jan-2008 #43

Closed
kpreid opened this issue Apr 16, 2015 · 2 comments
Closed

Code Review use-right-element-stack-18-Jan-2008 #43

kpreid opened this issue Apr 16, 2015 · 2 comments

Comments

@kpreid
Copy link
Contributor

kpreid commented Apr 16, 2015

Original issue 43 created by mikesamuel on 2008-01-21T05:30:27.000Z:

*mikesamuel/use-right-element-stack-18-Jan-2008@413 | mikesamuel |
2008-01-18 11:54:02 -0800 (Fri, 18 Jan 2008)

Description:

Make sure that all the places where we parse HTML & XML are using the proper
element stack implementation.

Affected Paths:
M //trunk/src/java/com/google/caja/parser/html/DomParser.java
M //trunk/src/java/com/google/caja/plugin/PluginCompiler.java
M //trunk/src/java/com/google/caja/plugin/PluginCompilerMain.java
M //trunk/src/javatests/com/google/caja/lexer/htmllexergolden1.txt
M //trunk/src/javatests/com/google/caja/lexer/htmllexerinput1.html
M //trunk/src/javatests/com/google/caja/parser/html/DomParserTest.java
M //trunk/src/javatests/com/google/caja/plugin/GxpCompilerTest.java
M //trunk/src/javatests/com/google/caja/plugin/GxpValidatorTest.java
M //trunk/src/javatests/com/google/caja/plugin/HtmlCompiledPluginTest.java

Index: java/com/google/caja/parser/html/DomParser.java
===================================================================
--- java/com/google/caja/parser/html/DomParser.java     (revision 411)
+++ java/com/google/caja/parser/html/DomParser.java     (working copy)
@@ -46,12 +46,6 @@
  * @author mikesamuel@gmail.com
  */
 public final class DomParser {
-  public static DomTree parseDocument(TokenQueue<HtmlTokenType> tokens)
-      throws ParseException {
-    return parseDocument(
-        tokens, OpenElementStack.Factory.createXmlElementStack());
-  }
-
   public static DomTree parseDocument(
       TokenQueue<HtmlTokenType> tokens, OpenElementStack elementStack)
       throws ParseException {
@@ -80,15 +74,6 @@
   /**
    * Parses a snippet of markup.
    */
-  public static DomTree.Fragment parseFragment(TokenQueue<HtmlTokenType>
tokens)
-      throws ParseException {
-    return parseFragment(
-        tokens, OpenElementStack.Factory.createXmlElementStack());
-  }
-
-  /**
-   * Parses a snippet of markup.
-   */
   public static DomTree.Fragment parseFragment(
       TokenQueue<HtmlTokenType> tokens, OpenElementStack elementStack)
       throws ParseException {
Index: java/com/google/caja/plugin/PluginCompiler.java
===================================================================
--- java/com/google/caja/plugin/PluginCompiler.java     (revision 411)
+++ java/com/google/caja/plugin/PluginCompiler.java     (working copy)
@@ -22,6 +22,7 @@
 import com.google.caja.parser.css.CssTree;
 import com.google.caja.parser.html.DomParser;
 import com.google.caja.parser.html.DomTree;
+import com.google.caja.parser.html.OpenElementStack;
 import com.google.caja.parser.js.*;
 import com.google.caja.plugin.GxpCompiler.BadContentException;
 import com.google.caja.reporting.Message;
@@ -495,7 +496,8 @@
       TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
           lexer, node.getFilePosition().source(),
           Criterion.Factory.<Token<HtmlTokenType>>optimist());
-      DomTree doc = DomParser.parseDocument(tq);
+      DomTree doc = DomParser.parseDocument(
+          tq, OpenElementStack.Factory.createXmlElementStack());
       tq.expectEmpty();
       if (!(doc instanceof DomTree.Tag)) {
         throw new ParseException(new Message(
Index: java/com/google/caja/plugin/PluginCompilerMain.java
===================================================================
--- java/com/google/caja/plugin/PluginCompilerMain.java (revision 411)
+++ java/com/google/caja/plugin/PluginCompilerMain.java (working copy)
@@ -32,6 +32,7 @@
 import com.google.caja.parser.css.CssParser;
 import com.google.caja.parser.css.CssTree;
 import com.google.caja.parser.html.DomParser;
+import com.google.caja.parser.html.OpenElementStack;
 import com.google.caja.parser.js.Parser;
 import com.google.caja.parser.js.Statement;
 import com.google.caja.reporting.Message;
@@ -241,7 +242,8 @@
       lexer.setTreatedAsXml(true);
       TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
           lexer, is, Criterion.Factory.<Token<HtmlTokenType>>optimist());
-      input = DomParser.parseDocument(tq);
+      input = DomParser.parseDocument(
+          tq, OpenElementStack.Factory.createXmlElementStack());
       tq.expectEmpty();
     } else if (path.endsWith(".css")) {
       CssLexer lexer = new CssLexer(cp);
Index: javatests/com/google/caja/lexer/htmllexergolden1.txt
===================================================================
--- javatests/com/google/caja/lexer/htmllexergolden1.txt        (revision 411)
+++ javatests/com/google/caja/lexer/htmllexergolden1.txt        (working copy)
@@ -198,3 +198,9 @@
 TEXT       [\n\n]  :  htmllexerinput1.html:78+8@1834 - 80+1@1836
 DIRECTIVE  [<![CDATA[ No such thing as a CDATA>]  : 
htmllexerinput1.html:80+1@1836 - 36@1871
 TEXT       [ section in HTML ]]>\n]  :  htmllexerinput1.html:80+36@1871 -
81+1@1892
+TAGBEGIN   [<script]  :  htmllexerinput1.html:81+1@1892 - 8@1899
+TAGEND     [>]  :  htmllexerinput1.html:81+8@1899 - 9@1900
+UNESCAPED  [a<b]  :  htmllexerinput1.html:81+9@1900 - 12@1903
+TAGBEGIN   [</script]  :  htmllexerinput1.html:81+12@1903 - 20@1911
+TAGEND     [>]  :  htmllexerinput1.html:81+20@1911 - 21@1912
+TEXT       [\n]  :  htmllexerinput1.html:81+21@1912 - 82+1@1913
Index: javatests/com/google/caja/lexer/htmllexerinput1.html
===================================================================
--- javatests/com/google/caja/lexer/htmllexerinput1.html        (revision 411)
+++ javatests/com/google/caja/lexer/htmllexerinput1.html        (working copy)
@@ -78,3 +78,4 @@
 </html>

 <![CDATA[ No such thing as a CDATA> section in HTML ]]>
+<script>a<b</script>
Index: javatests/com/google/caja/parser/html/DomParserTest.java
===================================================================
--- javatests/com/google/caja/parser/html/DomParserTest.java    (revision 411)
+++ javatests/com/google/caja/parser/html/DomParserTest.java    (working copy)
@@ -94,7 +94,8 @@

   public void testParseDom() throws Exception {
     TokenQueue<HtmlTokenType> tq = tokenizeTestInput(DOM1_XML, true);
-    DomTree t = DomParser.parseDocument(tq);
+    DomTree t = DomParser.parseDocument(
+        tq, OpenElementStack.Factory.createXmlElementStack());
     StringBuilder actual = new StringBuilder();
     t.format(new MessageContext(), actual);
     assertEquals(DOM1_GOLDEN, actual.toString());
Index: javatests/com/google/caja/plugin/GxpCompilerTest.java
===================================================================
--- javatests/com/google/caja/plugin/GxpCompilerTest.java       (revision 411)
+++ javatests/com/google/caja/plugin/GxpCompilerTest.java       (working copy)
@@ -26,6 +26,7 @@
 import com.google.caja.parser.ParseTreeNode;
 import com.google.caja.parser.html.DomParser;
 import com.google.caja.parser.html.DomTree;
+import com.google.caja.parser.html.OpenElementStack;
 import com.google.caja.parser.js.FunctionDeclaration;
 import com.google.caja.reporting.EchoingMessageQueue;
 import com.google.caja.reporting.Message;
@@ -72,7 +73,8 @@
         new PrintWriter(new OutputStreamWriter(System.out)), mc);
     TokenQueue<HtmlTokenType> tq = TestUtil.parseXml(
         getClass(), "gxpcompilerinput1.gxp", mq);
-    DomTree.Tag domTree = (DomTree.Tag) DomParser.parseDocument(tq);
+    DomTree.Tag domTree = (DomTree.Tag) DomParser.parseDocument(
+        tq, OpenElementStack.Factory.createXmlElementStack());
     GxpCompiler gxpc = new GxpCompiler(mq, makeTestPluginMeta());
     GxpCompiler.TemplateSignature sig =
gxpc.compileTemplateSignature(domTree);
     ParseTreeNode compiled = gxpc.compileDocument(sig);
@@ -94,7 +96,8 @@
         new PrintWriter(new OutputStreamWriter(System.out)), mc);
     TokenQueue<HtmlTokenType> tq = TestUtil.parseXml(
         getClass(), "gxpcompilerinput2.gxp", mq);
-    DomTree.Tag domTree = (DomTree.Tag) DomParser.parseDocument(tq);
+    DomTree.Tag domTree = (DomTree.Tag) DomParser.parseDocument(
+        tq, OpenElementStack.Factory.createXmlElementStack());
     GxpCompiler gxpc = new GxpCompiler(mq, makeTestPluginMeta());
     GxpCompiler.TemplateSignature sig =
gxpc.compileTemplateSignature(domTree);
     ParseTreeNode compiled = gxpc.compileDocument(sig);
@@ -132,9 +135,11 @@
         new PrintWriter(new OutputStreamWriter(System.out)), mc);

     DomTree.Tag gxp2 = (DomTree.Tag) DomParser.parseDocument(
-        TestUtil.parseXml(getClass(), "gxpcompilerinput3.gxp", mq));
+        TestUtil.parseXml(getClass(), "gxpcompilerinput3.gxp", mq),
+        OpenElementStack.Factory.createXmlElementStack());
     DomTree.Tag gxp3 = (DomTree.Tag) DomParser.parseDocument(
-        TestUtil.parseXml(getClass(), "gxpcompilerinput4.gxp", mq));
+        TestUtil.parseXml(getClass(), "gxpcompilerinput4.gxp", mq),
+        OpenElementStack.Factory.createXmlElementStack());
     GxpCompiler gxpc = new GxpCompiler(mq, makeTestPluginMeta());
     GxpCompiler.TemplateSignature sig2 = gxpc.compileTemplateSignature(gxp2),
                                   sig3 = gxpc.compileTemplateSignature(gxp3);
@@ -394,7 +399,8 @@
       lexer.setTreatedAsXml(true);
       TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
           lexer, is, Criterion.Factory.<Token<HtmlTokenType>>optimist());
-      doms[i] = (DomTree.Tag) DomParser.parseDocument(tq);
+      doms[i] = (DomTree.Tag) DomParser.parseDocument(
+          tq, OpenElementStack.Factory.createXmlElementStack());
       tq.expectEmpty();
     }

@@ -474,7 +480,8 @@
       lexer.setTreatedAsXml(true);
       TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
           lexer, is, Criterion.Factory.<Token<HtmlTokenType>>optimist());
-      doms[i] = (DomTree.Tag) DomParser.parseDocument(tq);
+      doms[i] = (DomTree.Tag) DomParser.parseDocument(
+          tq, OpenElementStack.Factory.createXmlElementStack());
       tq.expectEmpty();
     }

Index: javatests/com/google/caja/plugin/GxpValidatorTest.java
===================================================================
--- javatests/com/google/caja/plugin/GxpValidatorTest.java      (revision 411)
+++ javatests/com/google/caja/plugin/GxpValidatorTest.java      (working copy)
@@ -23,6 +23,7 @@
 import com.google.caja.parser.AncestorChain;
 import com.google.caja.parser.html.DomParser;
 import com.google.caja.parser.html.DomTree;
+import com.google.caja.parser.html.OpenElementStack;
 import com.google.caja.reporting.EchoingMessageQueue;
 import com.google.caja.reporting.MessageContext;
 import com.google.caja.reporting.MessageQueue;
@@ -77,7 +78,8 @@
     lexer.setTreatedAsXml(true);
     TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
         lexer, is, Criterion.Factory.<Token<HtmlTokenType>>optimist());
-    DomTree t = DomParser.parseDocument(tq);
+    DomTree t = DomParser.parseDocument(
+        tq, OpenElementStack.Factory.createXmlElementStack());
     assertEquals(html, valid,
                  new GxpValidator(mq).validate(new
AncestorChain<DomTree>(t)));
   }
Index: javatests/com/google/caja/plugin/HtmlCompiledPluginTest.java
===================================================================
--- javatests/com/google/caja/plugin/HtmlCompiledPluginTest.java       
(revision 411)
+++ javatests/com/google/caja/plugin/HtmlCompiledPluginTest.java       
(working copy)
@@ -20,6 +20,7 @@
 import com.google.caja.parser.AncestorChain;
 import com.google.caja.parser.html.DomParser;
 import com.google.caja.parser.html.DomTree;
+import com.google.caja.parser.html.OpenElementStack;
 import com.google.caja.parser.js.Block;
 import com.google.caja.reporting.EchoingMessageQueue;
 import com.google.caja.reporting.MessageContext;
@@ -340,7 +341,7 @@
         PluginEnvironment.CLOSED_PLUGIN_ENVIRONMENT);
     HtmlPluginCompiler compiler = new HtmlPluginCompiler(mq, meta);
     compiler.setMessageContext(mc);
-    DomTree html = parseHtml(gadgetSpec);
+    DomTree html = parseHtml(gadgetSpec, mq);
     if (html != null) { compiler.addInput(new AncestorChain<DomTree>(html)); }

     boolean failed = !compiler.run();
@@ -378,12 +379,13 @@
     }
   }

-  DomTree parseHtml(String html) throws Exception {
+  DomTree parseHtml(String html, MessageQueue mq) throws Exception {
     InputSource is
         = new InputSource(new URI("content", null, "/" + html, null));
     StringReader in = new StringReader(html);
     TokenQueue<HtmlTokenType> tq = DomParser.makeTokenQueue(is, in, false);
     if (tq.isEmpty()) { return null; }
-    return DomParser.parseFragment(tq);
+    return DomParser.parseFragment(
+        tq, OpenElementStack.Factory.createHtml5ElementStack(mq));
   }
 }
@kpreid
Copy link
Contributor Author

kpreid commented Apr 16, 2015

Comment #1 originally posted by anil262646 on 2008-01-23T12:02:35.000Z:

<empty>

@kpreid
Copy link
Contributor Author

kpreid commented Apr 16, 2015

Comment #2 originally posted by metaweta on 2008-01-25T21:20:38.000Z:

LGTM

@kpreid kpreid closed this as completed Apr 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant