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

withNullString value is printed without quotes when QuoteMode.ALL is specified; add QuoteMode.ALL_NON_NULL

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.3, 1.4
    • Fix Version/s: 1.5
    • Component/s: Printer
    • Labels:

      Description

      When setting QuoteMode.ALL is set we expect all values to be quoted, even those set as a default. This works in Commons 1.2 but doesn't in 1.4.

      Consider the following program:

      import org.apache.commons.csv.QuoteMode;
      import org.apache.commons.csv.CSVFormat;
      import org.apache.commons.csv.CSVPrinter;
      
      public class CommonsCsvIsSlightlyBroken {
          
          public static void main(String[] args) throws Exception {
              CSVFormat format = CSVFormat.EXCEL
                  .withNullString("N/A")
                  .withIgnoreSurroundingSpaces(true)
                  .withQuoteMode(QuoteMode.ALL);
              CSVPrinter printer = new CSVPrinter(System.out, format);
              printer.printRecord(new Object[] { null, "Hello", null, "World" });
          }
      }
      

      For 1.2 we get quoted output:

      richard@kichemaru:~/$ java -cp ~/.m2/repository/org/apache/commons/commons-csv/1.2/commons-csv-1.2.jar:. CommonsCsvIsSlightlyBroken
      "N/A","Hello","N/A","World"
      

      When run with 1.4 we get unquoted output for default fields:

      richard@kichemaru:~/$ java -cp ~/.m2/repository/org/apache/commons/commons-csv/1.4/commons-csv-1.4.jar:. CommonsCsvIsSlightlyBroken
      N/A,"Hello",N/A,"World"
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                zcacrgw Richard Wheeldon
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: