Uploaded image for project: 'Commons CSV'
  1. Commons CSV
  2. CSV-200

CSVFormat cannot read its own output if input contain escape character followed by quote character

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.4
    • None
    • Parser
    • None

    Description

      I can format CSV using CSVFormat that is subsequently unparsable by CSVFormat, the test below illustrates the failure:

      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());
              }
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              vladimir.eatwell Vladimir Eatwell
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: