You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2013/04/01 23:48:22 UTC

svn commit: r1463310 - in /maven/doxia/doxia/trunk/doxia-core/src: main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java test/resources/test.xhtml

Author: rfscholte
Date: Mon Apr  1 21:48:22 2013
New Revision: 1463310

URL: http://svn.apache.org/r1463310
Log:
[DOXIA-407] EmptyStackException when <dt> omitted 

Added:
    maven/doxia/doxia/trunk/doxia-core/src/test/resources/test.xhtml
Modified:
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java

Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java?rev=1463310&r1=1463309&r2=1463310&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java Mon Apr  1 21:48:22 2013
@@ -71,6 +71,9 @@ public class XhtmlBaseParser
     /** Used to recognize the case of img inside figure. */
     private boolean inFigure;
 
+    /** Used to wrap the definedTerm with its definition, even when one is omitted */
+    boolean hasDefinitionListItem = false;
+
     /** Decoration properties, eg for texts. */
     private final SinkEventAttributeSet decoration = new SinkEventAttributeSet();
 
@@ -472,11 +475,21 @@ public class XhtmlBaseParser
         }
         else if ( parser.getName().equals( HtmlMarkup.DT.toString() ) )
         {
+            if ( hasDefinitionListItem )
+            {
+                //close previous listItem
+                sink.definitionListItem_();
+            }    
             sink.definitionListItem( attribs );
+            hasDefinitionListItem = true;
             sink.definedTerm( attribs );
         }
         else if ( parser.getName().equals( HtmlMarkup.DD.toString() ) )
         {
+            if( !hasDefinitionListItem )
+            {
+                sink.definitionListItem( attribs );
+            }
             sink.definition( attribs );
         }
         else if ( ( parser.getName().equals( HtmlMarkup.B.toString() ) )
@@ -613,6 +626,11 @@ public class XhtmlBaseParser
         }
         else if ( parser.getName().equals( HtmlMarkup.DL.toString() ) )
         {
+            if( hasDefinitionListItem )
+            {
+                sink.definitionListItem_();
+                hasDefinitionListItem = false;
+            }
             sink.definitionList_();
         }
         else if ( parser.getName().equals( HtmlMarkup.DT.toString() ) )
@@ -623,6 +641,7 @@ public class XhtmlBaseParser
         {
             sink.definition_();
             sink.definitionListItem_();
+            hasDefinitionListItem = false;
         }
         else if ( ( parser.getName().equals( HtmlMarkup.B.toString() ) )
                 || ( parser.getName().equals( HtmlMarkup.STRONG.toString() ) ) )

Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java?rev=1463310&r1=1463309&r2=1463310&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java Mon Apr  1 21:48:22 2013
@@ -26,8 +26,6 @@ import org.apache.maven.doxia.sink.SinkE
 import org.apache.maven.doxia.sink.SinkEventElement;
 import org.apache.maven.doxia.sink.SinkEventTestingSink;
 
-import org.codehaus.plexus.PlexusTestCase;
-
 /**
  * Test for XhtmlBaseParser.
  *
@@ -36,11 +34,26 @@ import org.codehaus.plexus.PlexusTestCas
  * @since 1.1
  */
 public class XhtmlBaseParserTest
-    extends PlexusTestCase
+    extends AbstractParserTest
 {
     private XhtmlBaseParser parser;
     private final SinkEventTestingSink sink = new SinkEventTestingSink();
 
+
+    @Override
+    protected Parser createParser()
+    {
+        parser = new XhtmlBaseParser();
+        parser.getLog().setLogLevel( Log.LEVEL_ERROR );
+        return parser;
+    }
+
+    @Override
+    protected String outputExtension()
+    {
+        return "xhtml";
+    }
+
     @Override
     protected void setUp() throws Exception
     {
@@ -727,4 +740,28 @@ public class XhtmlBaseParserTest
         // ampersand should be un-escaped
         assertEquals( "http://ex.com/ex.jpg?v=l&l=e", attribs.getAttribute( "src" ) );
     }
+    
+    public void testUnbalancedDefinitionListItem() throws Exception
+    {
+        String text = "<body><dl><dt>key</dt><dd>value</dd></dl>" +
+                        "<dl><dd>value</dd></dl>" +
+                        "<dl><dt>key</dt></dl>" +
+                        "<dl></dl>" +
+                        "<dl><dd>value</dd><dt>key</dt></dl></body>";
+
+        parser.parse( text, sink );
+
+        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        assertEquals( it, "definitionList", "definitionListItem", "definedTerm", "text", "definedTerm_", "definition",
+                      "text", "definition_", "definitionListItem_", "definitionList_" );
+        assertEquals( it, "definitionList", "definitionListItem", "definition", "text", "definition_",
+                      "definitionListItem_", "definitionList_" );
+        assertEquals( it, "definitionList", "definitionListItem", "definedTerm", "text", "definedTerm_",
+                      "definitionListItem_", "definitionList_" );
+        assertEquals( it, "definitionList", "definitionList_" );
+        assertEquals( it, "definitionList", "definitionListItem", "definition", "text", "definition_",
+                      "definitionListItem_", "definitionListItem", "definedTerm", "text", "definedTerm_",
+                      "definitionListItem_", "definitionList_" );
+        assertFalse( it.hasNext() );
+    }
 }

Added: maven/doxia/doxia/trunk/doxia-core/src/test/resources/test.xhtml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/resources/test.xhtml?rev=1463310&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/resources/test.xhtml (added)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/resources/test.xhtml Mon Apr  1 21:48:22 2013
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>XHTML 1.0 Strict Example</title>
+ <script type="text/javascript">
+ //<![CDATA[
+ function loadpdf() {
+    document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
+ }
+ //]]>
+ </script>
+ </head>
+ <body onload="loadpdf()">
+ <p>This is an example of an
+ <abbr title="Extensible HyperText Markup Language">XHTML</abbr> 1.0 Strict document.<br />
+ <img id="validation-icon"
+    src="http://www.w3.org/Icons/valid-xhtml10"
+    alt="Valid XHTML 1.0 Strict" /><br />
+ <object id="pdf-object"
+    name="pdf-object"
+    type="application/pdf"
+    data="http://www.w3.org/TR/xhtml1/xhtml1.pdf"
+    width="100%"
+    height="500">
+ </object>
+ </p>
+ </body>
+</html>