zachwick / TableCSVExport

jQuery plugin to convert HTML table to CSV
http://zachwick.com/?p=87
42 stars 30 forks source link

strip HTML correctly and mask quotes #6

Closed rubo77 closed 11 years ago

zachwick commented 11 years ago

@rubo77 Thanks for your PR - I really like your additions, but I would like to propose two minor tweaks before this PR is accepted.

  1. From RFC-4180 (Common Format and MIME Type for Comma-Separated Values (CSV) Files):
 5.  Each field may or may not be enclosed in double quotes (however
      some programs, such as Microsoft Excel, do not use double quotes
      at all).  If fields are not enclosed with double quotes, then
      double quotes may not appear inside the fields.  For example:

      "aaa","bbb","ccc" CRLF
      zzz,yyy,xxx

6. Fields containing line breaks (CRLF), double quotes, and commas
    should be enclosed in double-quotes.  For example:

    "aaa","b CRLF
    bb","ccc" CRLF
    zzz,yyy,xxx

7.  If double-quotes are used to enclose fields, then a double-quote
    appearing inside a field must be escaped by preceding it with
    another double quote.  For example:

    "aaa","b""bb","ccc"

How this applies to your changes, is that I would ask that instead of masking " with a \, you instead mask " character with a " character (from point 7 above). Also, recall that at invocation, the code can insert an additional column (the extraHeader and extraData attributes). If these attributes are non-null, they are not wrapped in double quotes with the rest of the data. While they don't have to be wrapped in double quotes to keep with the spec, they probably should be just for consistency. Thanks again for you work, it is really appreciated.

zachwick commented 11 years ago

I have implemented the changes that suggested, so I will pull in your PR, and then apply the changes. Thanks again for your commits!