[CSV-149]/[CSV-195] fix line number is not proper at EOF (#60)

This commit is contained in:
Chen 2020-06-02 03:53:07 +08:00 committed by GitHub
parent d6845084c0
commit ad11cd14d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 9 deletions

View File

@ -125,7 +125,8 @@ final class ExtendedBufferedReader extends BufferedReader {
@Override
public int read() throws IOException {
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++;
}
lastChar = current;

View File

@ -644,11 +644,11 @@ public class CSVParserTest {
assertEquals(2, record.getRecordNumber());
assertEquals(2, parser.getRecordNumber());
assertNotNull(record = parser.nextRecord());
assertEquals(8, parser.getCurrentLineNumber());
assertEquals(9, parser.getCurrentLineNumber());
assertEquals(3, record.getRecordNumber());
assertEquals(3, parser.getRecordNumber());
assertNull(record = parser.nextRecord());
assertEquals(8, parser.getCurrentLineNumber());
assertEquals(9, parser.getCurrentLineNumber());
assertEquals(3, parser.getRecordNumber());
}
}
@ -1192,11 +1192,11 @@ public class CSVParserTest {
assertNotNull(parser.nextRecord());
assertEquals(2, parser.getCurrentLineNumber());
assertNotNull(parser.nextRecord());
// Still 2 because the last line is does not have EOL chars
assertEquals(2, parser.getCurrentLineNumber());
// Read EOF without EOL should 3
assertEquals(3, parser.getCurrentLineNumber());
assertNull(parser.nextRecord());
// Still 2 because the last line is does not have EOL chars
assertEquals(2, parser.getCurrentLineNumber());
// Read EOF without EOL should 3
assertEquals(3, parser.getCurrentLineNumber());
}
}

View File

@ -24,10 +24,8 @@ import java.io.StringReader;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@Disabled
public class JiraCsv149Test {
private static final String CR_LF = "\r\n";