From bd779a5d8af6218cd6b8ef1e265b3c5626e1eded Mon Sep 17 00:00:00 2001 From: Gray Watson Date: Fri, 15 Feb 2019 14:46:01 -0500 Subject: [PATCH] Fixed problem with blank line in the middle of the output. --- src/main/java/com/j256/simplecsv/processor/CsvProcessor.java | 4 ++-- src/main/javadoc/doc-files/changelog.txt | 3 +++ .../java/com/j256/simplecsv/processor/CsvProcessorTest.java | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/j256/simplecsv/processor/CsvProcessor.java b/src/main/java/com/j256/simplecsv/processor/CsvProcessor.java index e7b3af5..2fd11c2 100644 --- a/src/main/java/com/j256/simplecsv/processor/CsvProcessor.java +++ b/src/main/java/com/j256/simplecsv/processor/CsvProcessor.java @@ -1278,7 +1278,7 @@ private void processQuotedColumn(LineInfo lineInfo, BufferedReader bufferedReade int sectionEnd = linePos; StringBuilder sb = null; - while (linePos < line.length()) { + while (true) { // look for the next quote sectionEnd = line.indexOf(columnQuote, linePos); @@ -1294,7 +1294,7 @@ private void processQuotedColumn(LineInfo lineInfo, BufferedReader bufferedReade } // add the end of the line sb.append(line, sectionStart, line.length()); - // is this right if the line termination of the file doesn't match the system? + // add the line-termination in the middle of this column which will _hopefully_ match the file sb.append(lineTermination); // restart from the next line read line = nextLine; diff --git a/src/main/javadoc/doc-files/changelog.txt b/src/main/javadoc/doc-files/changelog.txt index a936503..49c1b44 100644 --- a/src/main/javadoc/doc-files/changelog.txt +++ b/src/main/javadoc/doc-files/changelog.txt @@ -1,3 +1,6 @@ +2.5: 2/15/2019 + * Fixed an immediate bug that I found when line-termination character an a blank line are inside a column. + 2.4: 2/15/2019 * Added handling of line-termination characters inside of columns if enabled. * Added a setting to load the fields from any super-classes _before_ the subclasses. diff --git a/src/test/java/com/j256/simplecsv/processor/CsvProcessorTest.java b/src/test/java/com/j256/simplecsv/processor/CsvProcessorTest.java index 21b4dea..d2ac1eb 100644 --- a/src/test/java/com/j256/simplecsv/processor/CsvProcessorTest.java +++ b/src/test/java/com/j256/simplecsv/processor/CsvProcessorTest.java @@ -850,6 +850,11 @@ public void testNewlineInColumn() throws Exception { str = "short\n" + "loooooooooooong\n" + "short"; basic = new Basic(0, str, 0, "foo", false); testReadWriteBasic(processor, basic); + + // blank line in the middle + str = "short\n\n" + "loooooooooooong\n" + "short"; + basic = new Basic(0, str, 0, "foo", false); + testReadWriteBasic(processor, basic); } @Test(expected = ParseException.class)