From: Charles Calvert Date: 2010-10-28T12:15:16+09:00 Subject: Re: FasterCSV - illegal quoting error - thought it was correct? On Wed, 27 Oct 2010 19:13:33 -0500, James Edward Gray II wrote in : >On Oct 27, 2010, at 5:58 PM, Gabriel Saravia wrote: > >> I have a csv file that includes many rows here's an example snippet >> including the header row: >> >> First Name, Last Name, Email, Password, Roles >> Sophia, Jackson, sjackson@example.com, abc123, UserRole1 >> Olivia, Davis, odavis@example.com, abc123, User Role2 >> Alexander, Thomas, athomas@example.com, abc123, "UserRole1, User Role2" > >> I thought that this was the correct way to handle this situation >> according to the standard. I do not want the quotes to be returned as >> part of my string, i just want the string that is the user roles. One >> set of quotes returns me the error illegal quoting, two sets of quotes >> returns me the same error. Shouldn't three sets include the quotes as >> part of the string? Well, it still returns me the same error. >> >> What am I doing wrong? thanks. > > The issue is the spaces after your commas. A quoted field must > begin with a quote, not a space. Here's an example: To expand on this, if you check the values returned for other rows, you'll find that they're being returned with the leading space included: irb(main):004:0> row = FasterCSV.parse('a, b, c') => [["a", " b", " c"]] irb(main):005:0> row[0] => ["a", " b", " c"] irb(main):006:0> row[0][0].size => 1 irb(main):007:0> row[0][1].size => 2 Note the difference between the first value and the second and third values. The latter have leading spaces. You should eliminate the spaces so that your rows look like this: First Name,Last Name,Email,Password,Roles Sophia,Jackson,sjackson@example.com,abc123,UserRole1 Olivia,Davis,odavis@example.com,abc123,User Role2 Alexander,Thomas,athomas@example.com,abc123,"UserRole1,User Role2" It's less easy for a human to read, but adheres to the RFC (http://tools.ietf.org/html/rfc4180#page-2). See section 2.4. -- Charles Calvert | Software Design/Development Celtic Wolf, Inc. | Project Management http://www.celticwolf.com/ | Technical Writing (703) 580-0210 | Research