Skip to content

Commit 61f5213

Browse files
committed
add public-api parser test for partial delimiter false-match at eof
1 parent 110e830 commit 61f5213

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,21 @@ void testPartialMultiCharacterDelimiterAtEOF() throws IOException {
16961696
}
16971697
}
16981698

1699+
/**
1700+
* A truncated multi-character delimiter at EOF must not be completed from the look-ahead buffer left dirty by an
1701+
* earlier non-matching peek in the same token.
1702+
*/
1703+
@Test
1704+
void testPartialMultiCharacterDelimiterAtEOFAfterMismatch() throws IOException {
1705+
final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get();
1706+
// The "[a]" peek leaves ']' in the look-ahead buffer; the trailing "[|" must not match "[|]".
1707+
try (CSVParser parser = format.parse(new StringReader("x[a][|"))) {
1708+
final CSVRecord record = parser.nextRecord();
1709+
assertEquals("x[a][|", record.get(0));
1710+
assertEquals(1, record.size());
1711+
}
1712+
}
1713+
16991714
@Test
17001715
void testProvidedHeader() throws Exception {
17011716
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");

0 commit comments

Comments
 (0)