You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Prokudin Mikhail (Jira)" <ji...@apache.org> on 2019/11/10 21:10:00 UTC

[jira] [Commented] (CSV-200) CSVFormat cannot read its own output if input contain escape character followed by quote character

    [ https://issues.apache.org/jira/browse/CSV-200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16971230#comment-16971230 ] 

Prokudin Mikhail commented on CSV-200:
--------------------------------------

I think it's not workaround. It's mutually exclusive approaches.

If you use quotes, you configure CSVFormat to escape special characters in value by wrapping value in quoets. If you use escape character, you configure CSVFormat to escape special characters by specified value.

Same _val,ue_ witn comma delimeter can be writen by both approaches:

1) "val,ue"

2) val\,ue with escape \ character

Could be good idea to change CSVFormat.validate() method to throw Exception when specified both parameters - Quotes and Escape character for except same conflict situations, but INFORMIX_UNLOAD format use both parameters. 

> CSVFormat cannot read its own output if input contain escape character followed by quote character
> --------------------------------------------------------------------------------------------------
>
>                 Key: CSV-200
>                 URL: https://issues.apache.org/jira/browse/CSV-200
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.4
>            Reporter: Vladimir Eatwell
>            Priority: Major
>
> I can format CSV using CSVFormat that is subsequently unparsable by CSVFormat, the test below illustrates the failure:
> {code}
> import org.apache.commons.csv.CSVFormat;
> import org.apache.commons.csv.CSVRecord;
> import org.apache.commons.csv.QuoteMode;
> import org.junit.Test;
> import java.io.StringReader;
> import java.util.List;
> public class CSVFormatTest {
>     @Test
>     public void parseFailure() throws Exception {
>         CSVFormat formatter = CSVFormat.DEFAULT;
>         formatter = formatter.withDelimiter(',');
>         formatter = formatter.withQuote('*');
>         formatter = formatter.withEscape('/');
>         formatter = formatter.withNullString("NULL");
>         formatter = formatter.withIgnoreSurroundingSpaces(true);
>         formatter = formatter.withQuoteMode(QuoteMode.MINIMAL);
>         String formatted = formatter.format("bob/*", "token");
>         List<CSVRecord> parsed = formatter.parse(new StringReader(formatted)).getRecords();
>         for (CSVRecord record : parsed) {
>             System.out.println(record.size());
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)