Skip to content

Commit 0633c98

Browse files
committed
Skip byte counting at EOF in ExtendedBufferedReader.read (#615).
Sort members.
1 parent 5f60ca5 commit 0633c98

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Escape quote char in printWithEscapes when QuoteMode is NONE (#609).</action>
6161
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Quote value starting with comment marker in minimal quote mode (#610).</action>
6262
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Escape leading comment marker in printWithEscapes (#614).</action>
63+
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Skip byte counting at EOF in ExtendedBufferedReader.read (#615).</action>
6364
<!-- ADD -->
6465
<action type="add" dev="ggregory" due-to="Gary Gregory, Indy, Sylvia van Os" issue="CSV-307">Add an "Android Compatibility" section to the web site.</action>
6566
<action type="add" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-325">Add CSVParser.Builder.setByteOffset(long) (#604).</action>

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -691,27 +691,6 @@ void testGetBytePositionMultiCharacterDelimiterWithSupplementaryCharacter() thro
691691
}
692692
}
693693

694-
@Test
695-
void testGetBytePositionWithSingleByteCharset() throws IOException {
696-
// A single-byte charset cannot encode U+FFFF, the char value of the EOF sentinel.
697-
// Byte counting must skip the EOF read so a valid file parses without throwing.
698-
final String code = "a,b\nc,d\n";
699-
try (CSVParser parser = CSVParser.builder()
700-
.setReader(new StringReader(code))
701-
.setFormat(CSVFormat.DEFAULT)
702-
.setCharset(StandardCharsets.ISO_8859_1)
703-
.setTrackBytes(true)
704-
.get()) {
705-
final CSVRecord first = parser.nextRecord();
706-
final CSVRecord second = parser.nextRecord();
707-
assertNotNull(first);
708-
assertNotNull(second);
709-
assertNull(parser.nextRecord());
710-
assertEquals(0, first.getBytePosition());
711-
assertEquals(4, second.getBytePosition());
712-
}
713-
}
714-
715694
@Test
716695
void testGetBytePositionWithCharacterOffsetAndMultiBytePrefix() throws Exception {
717696
final String row0 = "é,x\n";
@@ -742,6 +721,27 @@ void testGetBytePositionWithCharacterOffsetAndMultiBytePrefix() throws Exception
742721
}
743722
}
744723

724+
@Test
725+
void testGetBytePositionWithSingleByteCharset() throws IOException {
726+
// A single-byte charset cannot encode U+FFFF, the char value of the EOF sentinel.
727+
// Byte counting must skip the EOF read so a valid file parses without throwing.
728+
final String code = "a,b\nc,d\n";
729+
try (CSVParser parser = CSVParser.builder()
730+
.setReader(new StringReader(code))
731+
.setFormat(CSVFormat.DEFAULT)
732+
.setCharset(StandardCharsets.ISO_8859_1)
733+
.setTrackBytes(true)
734+
.get()) {
735+
final CSVRecord first = parser.nextRecord();
736+
final CSVRecord second = parser.nextRecord();
737+
assertNotNull(first);
738+
assertNotNull(second);
739+
assertNull(parser.nextRecord());
740+
assertEquals(0, first.getBytePosition());
741+
assertEquals(4, second.getBytePosition());
742+
}
743+
}
744+
745745
@Test
746746
void testGetHeaderComment_HeaderComment1() throws IOException {
747747
try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_COMMENT, FORMAT_AUTO_HEADER)) {

0 commit comments

Comments
 (0)