Merge pull request #266 from mykolaf/delimcheck

Validate input to setDelimiter(String) for empty string
This commit is contained in:
Gary Gregory 2022-10-15 09:39:04 -04:00 committed by GitHub
commit 23c39b158e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -346,6 +346,9 @@ public final class CSVFormat implements Serializable {
if (containsLineBreak(delimiter)) {
throw new IllegalArgumentException("The delimiter cannot be a line break");
}
if (delimiter.isEmpty()) {
throw new IllegalArgumentException("The delimiter cannot be empty");
}
this.delimiter = delimiter;
return this;
}

View File

@ -1569,4 +1569,9 @@ public class CSVFormatTest {
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator());
}
@Test
public void testDelimiterEmptyStringThrowsException1() {
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").build());
}
}