This is an automated email from the ASF dual-hosted git repository.
ggregory 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 d6e494b [CSV-241] CSVFormat#valiadte() does not account for
llowDuplicateHeaderNames.
d6e494b is described below
commit d6e494b44d85540923b39eb4956a704ecee295b1
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jun 5 18:03:25 2019 -0400
[CSV-241] CSVFormat#valiadte() does not account for
llowDuplicateHeaderNames.
Applying a different version of the GitHub patch with adjustments to the
tests. Also remove trailing whitespace from CSVRecord.
Closes #43.
---
src/changes/changes.xml | 3 +++
src/main/java/org/apache/commons/csv/CSVFormat.java | 2 +-
src/main/java/org/apache/commons/csv/CSVRecord.java | 2 +-
src/test/java/org/apache/commons/csv/CSVFormatTest.java | 14 +++++++++++++-
4 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0a7aa45..4489273 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -38,6 +38,9 @@
<title>Release Notes</title>
</properties>
<body>
+ <release version="1.8" date="2019-MM-DD" description="Feature and bug fix
release (Java 8)">
+ <action issue="CSV-241" type="fix" dev="ggregory" due-to="LuckyIlam,
Gary Gregory">CSVFormat#valiadte() does not account for
allowDuplicateHeaderNames #43.</action>
+ </release>
<release version="1.7" date="2019-06-01" description="Feature and bug fix
release (Java 8)">
<action issue="CSV-233" type="add" dev="ggregory" due-to="Gary
Gregory">Add predefined CSVFormats for printing MongoDB CSV and TSV.</action>
<action issue="CSV-208" type="fix" dev="ggregory" due-to="Jurrie
Overgoor">Fix escape character for POSTGRESQL_TEXT and POSTGRESQL_CSV
formats.</action>
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java
b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 264f2f8..1f60785 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -1668,7 +1668,7 @@ public final class CSVFormat implements Serializable {
}
// validate header
- if (header != null) {
+ if (header != null && !allowDuplicateHeaderNames) {
final Set<String> dupCheck = new HashSet<>();
for (final String hdr : header) {
if (!dupCheck.add(hdr)) {
diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java
b/src/main/java/org/apache/commons/csv/CSVRecord.java
index 942a090..b1b3f99 100644
--- a/src/main/java/org/apache/commons/csv/CSVRecord.java
+++ b/src/main/java/org/apache/commons/csv/CSVRecord.java
@@ -281,7 +281,7 @@ public final class CSVRecord implements Serializable,
Iterable<String> {
*/
@Override
public String toString() {
- return "CSVRecord [comment='" + comment + "', recordNumber=" +
recordNumber + ", values=" +
+ return "CSVRecord [comment='" + comment + "', recordNumber=" +
recordNumber + ", values=" +
Arrays.toString(values) + "]";
}
diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index 6d30e37..2a74b6f 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -72,8 +72,20 @@ public class CSVFormatTest {
}
@Test(expected = IllegalArgumentException.class)
+ public void testDuplicateHeaderElementsFalse() {
+ CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(false).withHeader("A",
"A");
+ }
+
+ public void testDuplicateHeaderElementsTrue() {
+ CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(true).withHeader("A",
"A");
+ }
+
+ @Test
public void testDuplicateHeaderElements() {
- CSVFormat.DEFAULT.withHeader("A", "A");
+ final String[] header = { "A", "A" };
+ final CSVFormat format = CSVFormat.DEFAULT.withHeader(header);
+ assertEquals(2, format.getHeader().length);
+ assertArrayEquals(header, format.getHeader());
}
@Test