jpace121 / jquery-csv

Automatically exported from code.google.com/p/jquery-csv
MIT License
0 stars 0 forks source link

Parse doesn't handle quotes in the CSV, even if escaped #42

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

$.csv.toArrays("Testing,Two\n"); /* Works */
$.csv.toArrays("Testing\",Two\n"); /* Throws an "Illegal Quote" error */
$.csv.toArrays("Testing\\\",Two\n"); /* Also throws an "Illegal Quote error" */

What is the expected output? What do you see instead?

It should parse the quotes.  Right now looks like the only quotes that can be 
in the strings are if they are enclosing the field.

What version of the product are you using? On what operating system?

0.71

Please provide any additional information below.

Original issue reported on code.google.com by k...@atomicinfotech.com on 25 Apr 2014 at 5:40

GoogleCodeExporter commented 9 years ago
It is not only for the quotes. It is for delimiter in general. I tested it with 
delimiters like: [",',$] and then I had the delimiter escaped in the values. It 
fails for all. 

Original comment by razvan.l...@gmail.com on 7 May 2014 at 12:24

GoogleCodeExporter commented 9 years ago
Quotes are escaped in CSV using double-double quotes.

The following works because it's has an even number quotes:

 $.csv.toArrays("Testing,Two\n"); /* Works */

This fails because there are an odd number of quotes.

 {{{$.csv.toArrays("Testing\",Two\n"); /* Throws an "Illegal Quote" error */}}}

Also fails because there are an odd number of quotes.

{{{$.csv.toArrays("Testing\\\",Two\n"); /* Also throws an "Illegal Quote error" 
*/}}}

The following is valid CSV as per the specification:
$.csv.toArrays("Testing,Two\n");
$.csv.toArrays("Testing"",Two\n");
$.csv.toArrays("Testing"""",Two\n");

I know it seems weird that CSV escapes a quote with a quote but that's how the 
format is specified.

Original comment by evanpla...@gmail.com on 29 May 2014 at 3:27

GoogleCodeExporter commented 9 years ago
BTW, the examples you posted should result in the following output:

Testing,Two
Testing"",Two
Testing"""",Two

Note: newline characters are assumed to be non-visible in the output.

In JSON equivalent would be:
[
  [  
    "Testing",
    "Two"
  ],
    "Testing""",
    "Two"
  ],
  [
    "Testing""""",
    "Two"
  ]
]

All 3 entries will have 2 cells because you're not containing the comma 
separator within a pair of double-quotes.

I hope that clears things up.

Original comment by evanpla...@gmail.com on 29 May 2014 at 3:31