[DOXIA-537] NullPointerException parsing table cell with single space
git-svn-id: https://svn.apache.org/repos/asf/maven/doxia/doxia/trunk@1726441 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java b/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java
index e1fe52a..34f3e4e 100644
--- a/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java
+++ b/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java
@@ -133,12 +133,11 @@
it++;
}
- String[] pText = texts.toArray( new String[0] );
- for ( int i = 0; i < pText.length; i++ )
+ for ( String pText : texts )
{
List<Block> blocks = new ArrayList<Block>();
- blocks.add( parseLine( pText[i], new ByLineReaderSource( new StringReader( EMPTY_STRING ) ) ) );
+ blocks.add( parseLine( pText, new ByLineReaderSource( new StringReader( EMPTY_STRING ) ) ) );
cells.add( new TableCellBlock( blocks ) );
}
@@ -146,7 +145,6 @@
rows.add( new TableRowBlock( cells ) );
}
-
while ( ( l = source.getNextLine() ) != null && accept( l, source ) );
assert rows.size() >= 1;
@@ -157,7 +155,7 @@
private Block parseLine( String text, ByLineSource source )
throws ParseException
{
- if ( text.trim().length() > 0 )
+ if ( text.length() > 0 )
{
for ( BlockParser parser : parsers )
{
diff --git a/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java b/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
index fec0722..319b0d7 100644
--- a/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
+++ b/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
@@ -300,6 +300,21 @@
assertEquals( 9, result.split( "end:link\n" ).length );
}
+ public void testTable()
+ throws Exception
+ {
+ String result = locateAndParseTestSourceFile( "table" );
+
+ // DOXIA-537
+ // |1|2|3|
+ assertContainsLines( result, "begin:tableRow\nbegin:tableCell\ntext: 1\nend:tableCell\n\n\nbegin:tableCell\ntext: 2\nend:tableCell\n\n\nbegin:tableCell\ntext: 3\nend:tableCell\n" );
+ // |1||3|
+ assertContainsLines( result, "begin:tableRow\nbegin:tableCell\ntext: 1\nend:tableCell\n\n\nbegin:tableCell\ntext: 3\nend:tableCell\n" );
+ // |1| |3|
+ assertContainsLines( result, "begin:tableRow\nbegin:tableCell\ntext: 1\nend:tableCell\n\n\nbegin:tableCell\ntext: \nend:tableCell\n\n\nbegin:tableCell\ntext: 3\nend:tableCell\n" );
+
+ }
+
/** @throws Exception */
public void testTableWithLinks()
throws Exception
diff --git a/doxia-modules/doxia-module-confluence/src/test/resources/table.confluence b/doxia-modules/doxia-module-confluence/src/test/resources/table.confluence
index 227a8e0..c6fe22c 100644
--- a/doxia-modules/doxia-module-confluence/src/test/resources/table.confluence
+++ b/doxia-modules/doxia-module-confluence/src/test/resources/table.confluence
@@ -10,4 +10,19 @@
|| Version || Download || Date || Format ||
|0.1.1 | [Download|http://example.com/release.0.1.1/ex-win32-win32.x86.zip] | 12-12-2008 | zip |
|0.1.2 | [Download|http://example.com/release.0.1.2/ex-win32-win32.x86.zip] | 04-12-2008 | zip |
-|0.1.3 | [Download|http://example.com/release.0.1.3/ex-win32-win32.x86.zip] | 03-11-2008 | zip |
\ No newline at end of file
+|0.1.3 | [Download|http://example.com/release.0.1.3/ex-win32-win32.x86.zip] | 03-11-2008 | zip |
+
+Here is a 3 column table with headers, one row, and data in every column:
+
+||One||Two||Three||
+|1|2|3|
+
+Now there is no data in column Two
+
+||One||Two||Three||
+|1||3|
+
+Now there is a space in column Two
+
+||One||Two||Three||
+|1| |3|
\ No newline at end of file