This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new a23b784  [CSV-249] ArrayIndexOutOfBoundsException when trying to read 
record written by CSVPrinter using CSVParser with same format.
a23b784 is described below

commit a23b784c1c81c625fed587149e0c460366206fa4
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Sep 28 13:08:56 2019 -0400

    [CSV-249] ArrayIndexOutOfBoundsException when trying to read record
    written by CSVPrinter using CSVParser with same format.
    
    Add passing test.
---
 .../org/apache/commons/csv/issues/JiraCvs249.java  | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCvs249.java 
b/src/test/java/org/apache/commons/csv/issues/JiraCvs249.java
new file mode 100644
index 0000000..108fb6a
--- /dev/null
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCvs249.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.csv.issues;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.List;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVPrinter;
+import org.apache.commons.csv.CSVRecord;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JiraCvs249 {
+
+    @Test
+    public void testJiraCsv249() throws IOException {
+
+        final CSVFormat csvFormat = CSVFormat.DEFAULT.withEscape('\\');
+
+        final StringWriter stringWriter = new StringWriter();
+
+        try (CSVPrinter printer = new CSVPrinter(stringWriter, csvFormat)) {
+            printer.printRecord("foo \\", "bar");
+        }
+        final StringReader stringReader = new 
StringReader(stringWriter.toString());
+        List<CSVRecord> records;
+        try (CSVParser parser = new CSVParser(stringReader, csvFormat)) {
+            records = parser.getRecords();
+        }
+
+        records.forEach(record -> {
+            Assert.assertEquals("foo \\", record.get(0));
+            Assert.assertEquals("bar", record.get(1));
+        });
+
+    }
+}
\ No newline at end of file

Reply via email to