Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit 5fd2133

Browse files
author
nimrodtalmon77
committed
Be more lenient about new lines in CSV.
http://gviz-reviews.appspot.com/7003
1 parent 0362411 commit 5fd2133

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/main/java/com/google/visualization/datasource/util/CsvDataSourceHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ public static DataTable read(Reader reader, List<ColumnDescription> columnDescri
102102
String[] line;
103103
boolean firstLine = true;
104104
while ((line = csvReader.readNext()) != null) {
105+
// Being lenient about newlines.
106+
// The reader reads them as lines with
107+
// one element ("").
108+
if ((line.length == 1) && (line[0].equals(""))) {
109+
// This is a new line.
110+
continue;
111+
}
112+
105113
if ((columnDescriptions != null) && (line.length != columnDescriptions.size())) {
106114
throw new CsvDataSourceException(
107115
ReasonType.INTERNAL_ERROR,

src/test/java/com/google/visualization/datasource/util/CsvDataSourceHelperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testRead() throws IOException, CsvDataSourceException {
6767
assertEquals(0, dataTable.getNumberOfRows());
6868

6969
// Null TableDescription.
70-
reader = new StringReader("1,2,3\n4,5,6");
70+
reader = new StringReader("\n\n\n1,2,3\n\n4,5,6\n\n\n\n\n");
7171
dataTable = CsvDataSourceHelper.read(reader, null, false);
7272
assertEquals(2, dataTable.getNumberOfRows());
7373
assertEquals(3, dataTable.getNumberOfColumns());

0 commit comments

Comments
 (0)