Uploaded image for project: 'Maven Doxia'
  1. Maven Doxia
  2. DOXIA-247

unable to parse document when the last character is '}'

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-alpha-11
    • 1.1
    • None
    • None

    Description

      When last character of a document is '}', maven doxia issues a, array out of bound exception. It tries to get next character to find out if we found a '}}' pair, but doesn't check bounds of document:

      org.apache.maven.doxia.parser.ParseException: String index out of range: 14
              at org.apache.maven.doxia.module.confluence.ConfluenceParser.parse(ConfluenceParser.java:139)
      ....
      Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 14
              at java.lang.String.charAt(String.java:558)
              at org.apache.maven.doxia.module.confluence.parser.ParagraphBlockParser.visit(ParagraphBlockParser.java:134)
              at org.apache.maven.doxia.module.confluence.ConfluenceParser.parse(ConfluenceParser.java:103)
              at org.apache.maven.doxia.module.confluence.ConfluenceParser.parse(ConfluenceParser.java:131)
      

      testcase:

      AppTest.java
      package org.apache.doxia.test.BUGTestCase;
      
      import java.io.StringReader;
      
      /**
       * Unit test for simple App.
       */
      public class AppTest 
      extends TestCase
      {
      	/**
      	 * Create the test case
      	 *
      	 * @param testName name of the test case
      	 */
      	public AppTest( String testName )
      	{
      		super( testName );
      	}
      
      	/**
      	 * @return the suite of tests being tested
      	 */
      	public static Test suite()
      	{
      		return new TestSuite( AppTest.class );
      	}
      
      	/**
      	 * Rigourous Test :-)
      	 * @throws ParseException 
      	 */
      	public void testEndBracket() throws ParseException
      	{
      		String document = "Test" +
      		"\n\n* list1"+
      		"\n\n* list2"+
      		"\n\n* list2"+
      		"\n{pre}123{/pre}";    			
      		StringWriter writer = new StringWriter();
      		ConfluenceParser parser = new ConfluenceParser();
      		XhtmlSink sink = new XhtmlSink(writer);
      		/* parsing with additional space at end works*/
      		parser.parse(new StringReader(document+" "), sink);
      		assertTrue("generated document should have a size >0",writer.toString().length()>0);
      		/* parsing with document ending in } fails*/
      		try{
      			parser.parse(new StringReader(document), sink);
      		} catch (Exception e){
      			e.printStackTrace();
      			fail("parsing with document ending in } should not fails");
      		}
      		assertTrue("generated document should have a size >0",writer.toString().length()>0);
      	}
      	/**
      	 * Rigourous Test :-)
      	 * @throws ParseException 
      	 */
      	public void testEndBracketInList() throws ParseException
      	{
      		String document1 = "Test" +
      		"\n\n* list1"+
      		"\n\n* list2"+
      		"\n\n* list2{pre}123{/pre} "+
      		"\n123";
      		String document2 = "Test" +
      		"\n\n* list1"+
      		"\n\n* list2"+
      		"\n\n* list2{pre}123{/pre}"+
      		"\n123";    			
      		StringWriter writer = new StringWriter();
      		ConfluenceParser parser = new ConfluenceParser();
      		XhtmlSink sink = new XhtmlSink(writer);
      		/* parsing with additional space at end of list item works*/
      		parser.parse(new StringReader(document1), sink);
      		assertTrue("generated document should have a size >0",writer.toString().length()>0);
      		/* parsing with end of list item ending in } fails*/
      		try{
      			parser.parse(new StringReader(document2), sink);
      		} catch (Exception e){
      			e.printStackTrace();
      			fail("parsing with end of list item ending in } should not fails");
      		}
      		assertTrue("generated document should have a size >0",writer.toString().length()>0);
      	}
      }
      

      Attachments

        Activity

          People

            ltheussl Lukas Theussl
            delbd David Delbecq
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: