You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2017/06/15 06:37:00 UTC
[jira] [Commented] (CSV-211) CSVFormat.format trims last delimiter
if the delimiter is a white space
[ https://issues.apache.org/jira/browse/CSV-211?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16050062#comment-16050062 ]
Gary Gregory commented on CSV-211:
----------------------------------
Hi Alpesh,
Thank you for your report.
Are you available to provide a (failing) unit test along with a fix. You can use a patch file or a GitHub PR.
Gary
> CSVFormat.format trims last delimiter if the delimiter is a white space
> -----------------------------------------------------------------------
>
> Key: CSV-211
> URL: https://issues.apache.org/jira/browse/CSV-211
> Project: Commons CSV
> Issue Type: Bug
> Affects Versions: 1.4
> Environment: Any.
> Reporter: Alpesh Kulkarni
> Priority: Minor
>
> The function CSVFormat.format() trims off the last delimiter if the delimiter is a white space character and the value in the last column is null.
> {code:java}
> public String format(Object... values) {
> StringWriter out = new StringWriter();
> try {
> (new CSVPrinter(out, this)).printRecord(values);
> return out.toString().trim();
> } catch (IOException var4) {
> throw new IllegalStateException(var4);
> }
> }
> {code}
> For example, consider the following records (\t = tab)-
> ID{color:red}\t{color}Name{color:red}\t{color}Country{color:red}\t{color}Age
> 1{color:red}\t{color}John Doe{color:red}\t{color}USA{color:red}\t{color}20
> 2{color:red}\t{color}Jane Doe{color:red}\t{color}USA{color:red}\t{color}
> The CSVFormat.format() on both the rows returns the following -
> ID{color:red}\t{color}Name{color:red}\t{color}Country{color:red}\t{color}Age
> 1{color:red}\t{color}John Doe{color:red}\t{color}USA{color:red}\t{color}20
> 2{color:red}\t{color}Jane Doe{color:red}\t{color}USA
> Note that there is a missing delimiter for the last column in the second record.
> This usually causes schema mismatch when we try and read back the CSV file as there is one less column in all the rows which have a null at the end.
> I feel the trim() is unnecessary while returning *out.toString()*
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)