garydgregory commented on code in PR #611:
URL: https://github.com/apache/commons-csv/pull/611#discussion_r3427889023


##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -1696,6 +1696,21 @@ void testPartialMultiCharacterDelimiterAtEOF() throws 
IOException {
         }
     }
 
+    /**
+     * A truncated multi-character delimiter at EOF must not be completed from 
the look-ahead buffer left dirty by an
+     * earlier non-matching peek in the same token.
+     */
+    @Test
+    void testPartialMultiCharacterDelimiterAtEOFAfterMismatch() throws 
IOException {
+        final CSVFormat format = 
CSVFormat.DEFAULT.builder().setDelimiter("[|]").get();
+        // The "[a]" peek leaves ']' in the look-ahead buffer; the trailing 
"[|" must not match "[|]".
+        try (CSVParser parser = format.parse(new StringReader("x[a][|"))) {

Review Comment:
   @rootvector2 
   
   Thank you for your update.
   
   In the future, please make magic strings like `"x[a][|"` a local variable 
such that you never have to check that the assertion below is checking for a 
possibly different value.
   



##########
src/test/java/org/apache/commons/csv/LexerTest.java:
##########
@@ -433,6 +433,19 @@ void testPartialMultiCharacterDelimiterAtEOF() throws 
IOException {
         }
     }
 
+    /**
+     * A truncated multi-character delimiter at EOF must not be accepted by 
reusing the look-ahead buffer left dirty by an
+     * earlier non-matching peek in the same token (CSV-324 only cleared the 
buffer once per token).
+     */
+    @Test
+    void testPartialMultiCharacterDelimiterAtEOFAfterMismatch() throws 
IOException {
+        final CSVFormat format = 
CSVFormat.DEFAULT.builder().setDelimiter("[|]").get();
+        // The "[a]" peek leaves ']' in the look-ahead buffer; the trailing 
"[|" must not match "[|]".
+        try (Lexer lexer = createLexer("x[a][|", format)) {

Review Comment:
   @rootvector2 
   
   Thank you for your update.
   
   In the future, please make magic strings like `"x[a][|"` a local variable 
such that you never have to check that the assertion below is checking for a 
possibly different value.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to