Skip to content

Commit d378f3e

Browse files
committed
[CSV-211] fix CSVFormat.format trims last delimiter if the delimiter is a white space
1 parent 57c7734 commit d378f3e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,9 @@ public String format(final Object... values) {
894894
final StringWriter out = new StringWriter();
895895
try (CSVPrinter csvPrinter = new CSVPrinter(out, this)) {
896896
csvPrinter.printRecord(values);
897-
return out.toString().trim();
897+
String res = out.toString();
898+
int len = recordSeparator != null ? res.length() - recordSeparator.length() : res.length();
899+
return res.substring(0, len);
898900
} catch (final IOException e) {
899901
// should not happen because a StringWriter does not do IO.
900902
throw new IllegalStateException(e);

0 commit comments

Comments
 (0)