This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new e9ed42af Add tests for line breaks in automatic CSV headers
e9ed42af is described below
commit e9ed42afa814b07ccf3be74ece6b25e16d59be54
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Oct 22 07:16:08 2026 -0400
Add tests for line breaks in automatic CSV headers
Verify that RFC4180 parsing preserves CR, LF, and CRLF in quoted header
names, consumes the header record, and supports lookup by the complete
names.
---
src/changes/changes.xml | 1 +
src/test/java/org/apache/commons/csv/CSVParserTest.java | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 235f8760..fcfd7d2d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -79,6 +79,7 @@
<action type="fix" dev="ggregory" due-to="Gary Gregory, saleem
malik">Keep an escaped value that equals the null string (#626).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Escape-mode
printer and parser mishandles value ending in multi-char delimiter prefix
(f001).</action>
<action type="fix" dev="ggregory" due-to="Jeff Lenamon, Gary
Gregory">Fix Javadoc for CSVPrinter.getRecordCount(): the header record written
by the constructor is counted (#633).</action>
+ <action type="fix" dev="ggregory" due-to="agamal026, Gary Gregory">Add
tests for line breaks in automatic CSV headers (#640).</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory, Indy, Sylvia van
Os" issue="CSV-307">Add an "Android Compatibility" section to the web
site.</action>
<action type="add" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory"
issue="CSV-325">Add CSVParser.Builder.setByteOffset(long) (#604).</action>
diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java
b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index 7e86fc00..d6269465 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -1409,6 +1409,22 @@ class CSVParserTest {
}
}
+ @ParameterizedTest
+ @ValueSource(strings = { "\r", "\n", "\r\n" })
+ void testHeaderWithLineBreaks(final String lineBreak) throws IOException {
+ final String firstHeader = "a" + lineBreak;
+ final String secondHeader = "b" + lineBreak;
+ final String csv = "\"" + firstHeader + "\",\"" + secondHeader +
"\"\r\n1,2\r\n";
+ final CSVFormat format = CSVFormat.RFC4180.builder().setHeader().get();
+ try (CSVParser parser = CSVParser.parse(csv, format)) {
+ assertEquals(Arrays.asList(firstHeader, secondHeader),
parser.getHeaderNames());
+ final List<CSVRecord> records = parser.getRecords();
+ assertEquals(1, records.size());
+ assertEquals("1", records.get(0).get(firstHeader));
+ assertEquals("2", records.get(0).get(secondHeader));
+ }
+ }
+
@Test
void testIgnoreCaseHeaderMapping() throws Exception {
final Reader reader = new StringReader("1,2,3");