Skip to content

Commit 23c39b1

Browse files
authored
Merge pull request apache#266 from mykolaf/delimcheck
Validate input to setDelimiter(String) for empty string
2 parents 550309e + 1da7570 commit 23c39b1

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ public Builder setDelimiter(final String delimiter) {
346346
if (containsLineBreak(delimiter)) {
347347
throw new IllegalArgumentException("The delimiter cannot be a line break");
348348
}
349+
if (delimiter.isEmpty()) {
350+
throw new IllegalArgumentException("The delimiter cannot be empty");
351+
}
349352
this.delimiter = delimiter;
350353
return this;
351354
}

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,4 +1569,9 @@ public void testWithSystemRecordSeparator() {
15691569
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
15701570
assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator());
15711571
}
1572+
1573+
@Test
1574+
public void testDelimiterEmptyStringThrowsException1() {
1575+
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").build());
1576+
}
15721577
}

0 commit comments

Comments
 (0)