diff --git a/pom.xml b/pom.xml
index 0b37e30d..5788fb34 100644
--- a/pom.xml
+++ b/pom.xml
@@ -257,6 +257,8 @@
src/test/resources/ferc.gov/transaction.txt
src/test/resources/**/*.bin
src/test/resources/CSV-259/sample.txt
+ src/test/resources/CSVFileParser/testCSV246.csv
+ src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt
@@ -375,6 +377,8 @@
src/test/resources/ferc.gov/transaction.txt
src/test/resources/**/*.bin
src/test/resources/CSV-259/sample.txt
+ src/test/resources/CSVFileParser/testCSV246.csv
+ src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt
diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
index 8e274f9d..413ef617 100644
--- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
@@ -93,11 +93,9 @@ public class CSVFileParserTest {
try (final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format)) {
for (final CSVRecord record : parser) {
String parsed = Arrays.toString(record.values());
- if (checkComments) {
- final String comment = record.getComment().replace("\n", "\\n");
- if (comment != null) {
- parsed += "#" + comment;
- }
+ String comment = record.getComment();
+ if (checkComments && comment != null) {
+ parsed += "#" + comment.replace("\n", "\\n");
}
final int count = record.size();
assertEquals(readTestData(testData), count + ":" + parsed, testFile.getName());
@@ -140,11 +138,9 @@ public class CSVFileParserTest {
try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
for (final CSVRecord record : parser) {
String parsed = Arrays.toString(record.values());
- if (checkComments) {
- final String comment = record.getComment().replace("\n", "\\n");
- if (comment != null) {
- parsed += "#" + comment;
- }
+ String comment = record.getComment();
+ if (checkComments && comment != null) {
+ parsed += "#" + comment.replace("\n", "\\n");
}
final int count = record.size();
assertEquals(readTestData(testData), count + ":" + parsed, testFile.getName());
diff --git a/src/test/resources/CSVFileParser/testCSV246.csv b/src/test/resources/CSVFileParser/testCSV246.csv
new file mode 100644
index 00000000..f01a2147
--- /dev/null
+++ b/src/test/resources/CSVFileParser/testCSV246.csv
@@ -0,0 +1,8 @@
+a,b,c,e,f
+# Very Long
+# Comment 2
+g,h,i,j,k
+# Very Long
+
+# Comment 3
+l,m,n,o,p
\ No newline at end of file
diff --git a/src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt b/src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt
new file mode 100644
index 00000000..cb7d21f0
--- /dev/null
+++ b/src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt
@@ -0,0 +1,10 @@
+testCSV246.csv CommentStart=# CheckComments
+Delimiter=<,> QuoteChar=<"> CommentStart=<#> SkipHeaderRecord:false
+5:[a, b, c, e, f]
+# Very Long
+# Comment 2
+5:[g, h, i, j, k]#Very Long\nComment 2
+# Very Long
+1:[]#Very Long
+# Comment 3
+5:[l, m, n, o, p]#Comment 3
\ No newline at end of file