Skip to content

Commit ed8dbf2

Browse files
committed
Clear escape delimiter buffer before peek in Lexer.isEscapeDelimiter()
(apache#608, apache#611). Refactor magic strings in tests
1 parent f685de6 commit ed8dbf2

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-326">CSVPrinter Reader printing with quote and escape can emit CSV that its parser cannot read back.</action>
5555
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-327">CSVParser applies maxRows to record numbers instead of rows produced when setRecordNumber(...) is used.</action>
5656
<action type="fix" dev="ggregory" due-to="OldTruckDriver, Gary Gregory" issue="CSV-326">Escape Reader values with quote and escape (#606).</action>
57-
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Clear escape delimiter buffer before peek in isEscapeDelimiter (#608).</action>
57+
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Clear escape delimiter buffer before peek in Lexer.isEscapeDelimiter() (#608, #611).</action>
5858
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Escape quote char in printWithEscapes when QuoteMode is NONE (#609).</action>
5959
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Quote value starting with comment marker in minimal quote mode (#610)..</action>
6060
<!-- ADD -->

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,9 +1704,10 @@ void testPartialMultiCharacterDelimiterAtEOF() throws IOException {
17041704
void testPartialMultiCharacterDelimiterAtEOFAfterMismatch() throws IOException {
17051705
final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get();
17061706
// The "[a]" peek leaves ']' in the look-ahead buffer; the trailing "[|" must not match "[|]".
1707-
try (CSVParser parser = format.parse(new StringReader("x[a][|"))) {
1707+
final String recordString = "x[a][|";
1708+
try (CSVParser parser = format.parse(new StringReader(recordString))) {
17081709
final CSVRecord record = parser.nextRecord();
1709-
assertEquals("x[a][|", record.get(0));
1710+
assertEquals(recordString, record.get(0));
17101711
assertEquals(1, record.size());
17111712
}
17121713
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ void testPartialMultiCharacterDelimiterAtEOF() throws IOException {
441441
void testPartialMultiCharacterDelimiterAtEOFAfterMismatch() throws IOException {
442442
final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get();
443443
// The "[a]" peek leaves ']' in the look-ahead buffer; the trailing "[|" must not match "[|]".
444-
try (Lexer lexer = createLexer("x[a][|", format)) {
445-
assertNextToken(EOF, "x[a][|", lexer);
444+
final String recordString = "x[a][|";
445+
try (Lexer lexer = createLexer(recordString, format)) {
446+
assertNextToken(EOF, recordString, lexer);
446447
}
447448
}
448449

0 commit comments

Comments
 (0)