[CSV-106] CSVFormat.format always append null.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1577011 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2014-03-13 00:16:57 +00:00
parent bf8f23c310
commit 73cc5246cf
2 changed files with 13 additions and 2 deletions

View File

@ -321,7 +321,10 @@ public final class CSVPrinter implements Flushable, Closeable {
* If an I/O error occurs * If an I/O error occurs
*/ */
public void println() throws IOException { public void println() throws IOException {
out.append(format.getRecordSeparator()); final String recordSeparator = format.getRecordSeparator();
if (recordSeparator != null) {
out.append(recordSeparator);
}
newRecord = true; newRecord = true;
} }

View File

@ -229,6 +229,14 @@ public class CSVFormatTest {
assertNotSame(formatWithHeader.getHeader(), headerCopy); assertNotSame(formatWithHeader.getHeader(), headerCopy);
} }
@Test
public void testNullRecordSeparatorCsv106() {
final CSVFormat format = CSVFormat.newFormat(';').withSkipHeaderRecord(true).withHeader("H1", "H2");
final String formatStr = format.format("A", "B");
assertNotNull(formatStr);
assertFalse(formatStr.endsWith("null"));
}
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void testQuoteCharSameAsCommentStartThrowsException() { public void testQuoteCharSameAsCommentStartThrowsException() {
CSVFormat.DEFAULT.withQuoteChar('!').withCommentStart('!').validate(); CSVFormat.DEFAULT.withQuoteChar('!').withCommentStart('!').validate();