[CSV-149]/[CSV-195] fix line number is not proper at EOF (#60)
This commit is contained in:
parent
d6845084c0
commit
ad11cd14d0
|
@ -125,7 +125,8 @@ final class ExtendedBufferedReader extends BufferedReader {
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
final int current = super.read();
|
final int current = super.read();
|
||||||
if (current == CR || current == LF && lastChar != CR) {
|
if ((current == CR || current == LF && lastChar != CR)
|
||||||
|
|| (current == END_OF_STREAM && lastChar != CR && lastChar != LF && lastChar != END_OF_STREAM)) {
|
||||||
eolCounter++;
|
eolCounter++;
|
||||||
}
|
}
|
||||||
lastChar = current;
|
lastChar = current;
|
||||||
|
|
|
@ -644,11 +644,11 @@ public class CSVParserTest {
|
||||||
assertEquals(2, record.getRecordNumber());
|
assertEquals(2, record.getRecordNumber());
|
||||||
assertEquals(2, parser.getRecordNumber());
|
assertEquals(2, parser.getRecordNumber());
|
||||||
assertNotNull(record = parser.nextRecord());
|
assertNotNull(record = parser.nextRecord());
|
||||||
assertEquals(8, parser.getCurrentLineNumber());
|
assertEquals(9, parser.getCurrentLineNumber());
|
||||||
assertEquals(3, record.getRecordNumber());
|
assertEquals(3, record.getRecordNumber());
|
||||||
assertEquals(3, parser.getRecordNumber());
|
assertEquals(3, parser.getRecordNumber());
|
||||||
assertNull(record = parser.nextRecord());
|
assertNull(record = parser.nextRecord());
|
||||||
assertEquals(8, parser.getCurrentLineNumber());
|
assertEquals(9, parser.getCurrentLineNumber());
|
||||||
assertEquals(3, parser.getRecordNumber());
|
assertEquals(3, parser.getRecordNumber());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1192,11 +1192,11 @@ public class CSVParserTest {
|
||||||
assertNotNull(parser.nextRecord());
|
assertNotNull(parser.nextRecord());
|
||||||
assertEquals(2, parser.getCurrentLineNumber());
|
assertEquals(2, parser.getCurrentLineNumber());
|
||||||
assertNotNull(parser.nextRecord());
|
assertNotNull(parser.nextRecord());
|
||||||
// Still 2 because the last line is does not have EOL chars
|
// Read EOF without EOL should 3
|
||||||
assertEquals(2, parser.getCurrentLineNumber());
|
assertEquals(3, parser.getCurrentLineNumber());
|
||||||
assertNull(parser.nextRecord());
|
assertNull(parser.nextRecord());
|
||||||
// Still 2 because the last line is does not have EOL chars
|
// Read EOF without EOL should 3
|
||||||
assertEquals(2, parser.getCurrentLineNumber());
|
assertEquals(3, parser.getCurrentLineNumber());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,8 @@ import java.io.StringReader;
|
||||||
import org.apache.commons.csv.CSVFormat;
|
import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVParser;
|
import org.apache.commons.csv.CSVParser;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@Disabled
|
|
||||||
public class JiraCsv149Test {
|
public class JiraCsv149Test {
|
||||||
|
|
||||||
private static final String CR_LF = "\r\n";
|
private static final String CR_LF = "\r\n";
|
||||||
|
|
Loading…
Reference in New Issue