Skip to content

Commit 822e653

Browse files
committed
Test cases for the scenarios described in SANDBOX-161:
* Double quotes (") should be escaped using two double quotes (""), rather than a backslash (\"). * Embedded line breaks are allowed and don't need to be escaped... just enclose the field in double quotes. * Because backslashes are not used to escape double quotes or line breaks, the backslashes themselves do not need to be escaped. git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@1065519 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6b422c8 commit 822e653

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,38 @@ public void testPrinter3() throws IOException {
5757
assertEquals("\"a, b\",\"b \"" + lineSeparator, sw.toString());
5858
}
5959

60+
public void testPrinter4() throws IOException {
61+
StringWriter sw = new StringWriter();
62+
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
63+
String[] line1 = {"a", "b\"c"};
64+
printer.println(line1);
65+
assertEquals("a,\"b\"\"c\"" + lineSeparator, sw.toString());
66+
}
67+
68+
public void testPrinter5() throws IOException {
69+
StringWriter sw = new StringWriter();
70+
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
71+
String[] line1 = {"a", "b\nc"};
72+
printer.println(line1);
73+
assertEquals("a,\"b\nc\"" + lineSeparator, sw.toString());
74+
}
75+
76+
public void testPrinter6() throws IOException {
77+
StringWriter sw = new StringWriter();
78+
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
79+
String[] line1 = {"a", "b\r\nc"};
80+
printer.println(line1);
81+
assertEquals("a,\"b\r\nc\"" + lineSeparator, sw.toString());
82+
}
83+
84+
public void testPrinter7() throws IOException {
85+
StringWriter sw = new StringWriter();
86+
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
87+
String[] line1 = {"a", "b\\c"};
88+
printer.println(line1);
89+
assertEquals("a,b\\c" + lineSeparator, sw.toString());
90+
}
91+
6092
public void testExcelPrinter1() throws IOException {
6193
StringWriter sw = new StringWriter();
6294
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.EXCEL_STRATEGY);

0 commit comments

Comments
 (0)