Skip to content

Commit 39d285d

Browse files
committed
https://github.com/manifold-systems/manifold/issues/622
- handle empty trailing values
1 parent 6f3fbf8 commit 39d285d

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

manifold-deps-parent/manifold-csv-rt/src/main/java/manifold/csv/rt/parser/CsvTokenizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ else if( quoted )
164164
: _content.charAt( _pos - 1 ) == '\r'
165165
? _pos - 1
166166
: _pos;
167-
int length = end - offset;
167+
int length = end > offset ? end - offset : 0;
168168
boolean emptyLine = length <= 0 && (_prevToken == null || _prevToken.isLastInRecord());
169169
if( !emptyLine )
170170
{

manifold-deps-parent/manifold-csv-test/src/test/java/manifold/csv/CsvTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import abc.csv.insurance_sample_comma.insurance_sample_commaItem;
2626
import abc.csv.Cake;
2727
import abc.csv.Cake.CakeItem;
28+
import abc.csv.MissingLastColumn;
2829
import java.io.IOException;
2930
import java.io.InputStreamReader;
3031
import java.math.BigDecimal;
@@ -37,9 +38,7 @@
3738

3839
import org.junit.Test;
3940

40-
41-
import static org.junit.Assert.assertEquals;
42-
import static org.junit.Assert.assertNotNull;
41+
import static org.junit.Assert.*;
4342

4443
public class CsvTest
4544
{
@@ -102,4 +101,23 @@ public void testIndentedFile()
102101
assertEquals(data[i][2], item.getCake());
103102
}
104103
}
104+
105+
@Test
106+
public void testMissingLastColumn()
107+
{
108+
MissingLastColumn items = MissingLastColumn.fromSource();
109+
assertEquals( 3, items.size() );
110+
111+
assertEquals( "", items.get( 0 ).getCol1() );
112+
assertEquals( 1, (int)items.get( 0 ).getCol2() );
113+
assertEquals( "", items.get( 0 ).getCol3() );
114+
115+
assertEquals( "", items.get( 1 ).getCol1() );
116+
assertEquals( 2, (int)items.get( 1 ).getCol2() );
117+
assertEquals( "", items.get( 1 ).getCol3() );
118+
119+
assertEquals( "", items.get( 2 ).getCol1() );
120+
assertNull( items.get( 2 ).getCol2() );
121+
assertEquals( "", items.get( 2 ).getCol3() );
122+
}
105123
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
col1,col2,col3
2+
,1,
3+
,2,
4+
,,

0 commit comments

Comments
 (0)