fix isssue csv-259 (#61)

* fix isssue csv-259

* add testcase for CSV259

* exclude csv259 test file

* organize the imports
This commit is contained in:
Chen 2020-03-17 22:51:01 +08:00 committed by GitHub
parent e503c568a1
commit 953a6de722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 0 deletions

View File

@ -256,6 +256,7 @@
<exclude>src/test/resources/ferc.gov/contract.txt</exclude> <exclude>src/test/resources/ferc.gov/contract.txt</exclude>
<exclude>src/test/resources/ferc.gov/transaction.txt</exclude> <exclude>src/test/resources/ferc.gov/transaction.txt</exclude>
<exclude>src/test/resources/**/*.bin</exclude> <exclude>src/test/resources/**/*.bin</exclude>
<exclude>src/test/resources/CSV-259/sample.txt</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
@ -373,6 +374,7 @@
<exclude>src/test/resources/ferc.gov/contract.txt</exclude> <exclude>src/test/resources/ferc.gov/contract.txt</exclude>
<exclude>src/test/resources/ferc.gov/transaction.txt</exclude> <exclude>src/test/resources/ferc.gov/transaction.txt</exclude>
<exclude>src/test/resources/**/*.bin</exclude> <exclude>src/test/resources/**/*.bin</exclude>
<exclude>src/test/resources/CSV-259/sample.txt</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -1408,6 +1408,7 @@ public final class CSVFormat implements Serializable {
if (pos > start) { if (pos > start) {
out.append(builder.substring(start, pos)); out.append(builder.substring(start, pos));
builder.setLength(0); builder.setLength(0);
pos = -1;
} }
if (c == LF) { if (c == LF) {
c = 'n'; c = 'n';

View File

@ -34,6 +34,8 @@ import java.io.PrintStream;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.io.Reader;
import java.io.FileReader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.BatchUpdateException; import java.sql.BatchUpdateException;
@ -310,6 +312,16 @@ public class CSVPrinterTest {
tryFormat(list, '"', '"', "\"\"\"\"\"\",\\\\,\"\\\"\"\\\""); tryFormat(list, '"', '"', "\"\"\"\"\"\",\\\\,\"\\\"\"\\\"");
} }
@Test
public void testCSV259() throws IOException {
final StringWriter sw = new StringWriter();
final Reader reader = new FileReader("src/test/resources/CSV-259/sample.txt");
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape('!').withQuote(null))) {
printer.print(reader);
assertEquals("x!,y!,z", sw.toString());
}
}
@Test @Test
public void testDelimeterQuoted() throws IOException { public void testDelimeterQuoted() throws IOException {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();

View File

@ -0,0 +1 @@
x,y,z