@@ -1512,4 +1512,26 @@ public void testPrintReaderWithoutQuoteToAppendable() throws IOException {
15121512 }
15131513 assertEquals (content , sb .toString ());
15141514 }
1515+
1516+ private void tryFormat (List <String > l , Character quote , Character escape , String expected ) throws IOException {
1517+ CSVFormat format = CSVFormat .DEFAULT .withQuote (quote ).withEscape (escape ).withRecordSeparator (null );
1518+ Appendable out = new StringBuilder ();
1519+ CSVPrinter printer = new CSVPrinter (out , format );
1520+ printer .printRecord (l );
1521+ printer .close ();
1522+ assertEquals (expected , out .toString ());
1523+ }
1524+
1525+ @ Test
1526+ public void testCSV135 () throws IOException {
1527+ List <String > l = new LinkedList <String >();
1528+ l .add ("\" \" " ); // ""
1529+ l .add ("\\ \\ " ); // \\
1530+ l .add ("\\ \" \\ " ); // \"\
1531+ tryFormat (l , null , null , "\" \" ,\\ \\ ,\\ \" \\ " ); // "",\\,\"\ (unchanged)
1532+ tryFormat (l , '"' , null , "\" \" \" \" \" \" ,\\ \\ ,\" \\ \" \" \\ \" " ); // """""",\\,"\""\" (quoted, and embedded DQ doubled)
1533+ tryFormat (l , null , '\\' , "\" \" ,\\ \\ \\ \\ ,\\ \\ \" \\ \\ " ); // "",\\\\,\\"\\ (escapes escaped, not quoted)
1534+ tryFormat (l , '"' , '\\' , "\" \\ \" \\ \" \" ,\" \\ \\ \\ \\ \" ,\" \\ \\ \\ \" \\ \\ \" " ); // "\"\"","\\\\","\\\"\\" (quoted, and embedded DQ & escape escaped)
1535+ tryFormat (l , '"' , '"' , "\" \" \" \" \" \" ,\\ \\ ,\" \\ \" \" \\ \" " ); // """""",\\,"\""\" (quoted, embedded DQ escaped)
1536+ }
15151537}
0 commit comments