According to this RFC http://tools.ietf.org/rfc/rfc4180.txt, a field should be fully double quoted, when something uncommon happens in it, doubling other DQUOTES inside (if there are any). For example:

;A string with a "double" quote in it;

should break parsing process. The correct variant would be:

;"A string with a ""double"" quote in it";

Current implementation will accept the former and will feed the fields values with subsequent lines until next double quote.
This should throw an exception with corresponding message about it, stopping parsing.

===

Splitting #1428272: Added support of encoding conversions to the CSV Parser, part 2.

Comments

OnkelTem’s picture

Title: RFC 4180 violation fix » Fix DQUOTES handling according to RFC 4180
Status: Active » Needs review
StatusFileSize
new3.52 KB
twistor’s picture

Status: Needs review » Needs work

I'm reluctant to change the behavior of the parser. It's been going strong now for a long time.

What we'll need are solid tests. I know there's an RFC and all, but people won't care if their Excel exports don't work, so we need a bunch of test data from common sources of CSV data to work with. Also, some at least one test that fails with the current parser that this one fixes.

twistor’s picture

If we had all of those tests, then #1369874: Don't roll own CSV parser; use PHP's native one could start to look like a more valid solution.

OnkelTem’s picture

@twistor

Parser
I agree that existing stuff must continue functioning as before and of course Excel products too.
From the other hand, algorithms should evolve, as the current implementation is unable to correctly parse DQUOTED data for example.

Test cases
I'm not a big fan of M$ apps, and have no good test cases ready at hand, but, of course, we need more tests (now there is only couple of simple, correct and latin-1-encoded .CSV files in the test folder).

fgetcsv()
I didn't know about fgetcsv(), but now after reading it's "man page" I found it's pretty good. I vote for giving it a chance, but to try it would require to introduce changes in ParserCSVIterator class which make it incompatible with current implementation.

Proposition
I propose to create three (or two - current and fgetcsv()) different implementations of CSVParser making appropriate one selectable for user on the parser configuration form.

What do you think?

twistor’s picture

What I meant about Excel files was that we need to assemble an assortment of CSV files, since there really no "one true way" to create a CSV file. I don't mean to put a huge burden on this issue, but I put the same burden on anyone who wants to drastically change the current CSV parser.

I'm not too concerned with changing ParserCSVIterator. If it turns out to be an issue, we can leave it, and move the fgets implementation to something else. That said, I would not want to have multiple CSV parsers included with Feeds. That would turn into all kinds of headaches. I think the ideal thing would be to fully develop the fgets parser someplace else, and move it in when it's mature.

Back to the issue.
Absolutely, we should support DQUOTED CSV files. I don't really use CSV files too much myself, and I would like to know if strict adherence to the spec would break things for current users. Specifically, requiring double quotes for quotes inside a column.

twistor’s picture

Issue summary: View changes

Updated summary

Niremizov’s picture

Issue summary: View changes

Suppose if could get ParserCSV to be more configurable, it could solve such issues. For example, at the moment such line (with ; as separator):

22B02 Arena_S Actau, mkr. 16, "Actau";test

Is be parsed as 1 column, becouse dquotes are not escaped. Would be nice if such behaviour could be configured.

Niremizov’s picture

StatusFileSize
new2.68 KB

Ok, here is patch that adds inside CSV Parser config form checkbox that allows to turn off Detecting of DQuotes inside file, probably his would be usefull for someone.

Niremizov’s picture

StatusFileSize
new3.01 KB

Added few fixes to prev. patch.

twistor’s picture

This shouldn't be an option, it should just work. Either the field is quoted or not, if not, ignore quotes inside.

I wonder how much things would break if we ported the CSV parser from 8.x-3.x.

damienmckenna’s picture

Status: Needs work » Needs review
Related issues: +#3004499: Drush feeds-import command ignores stored config for CSV parser
StatusFileSize
new2.9 KB

Rerolled, and simplified so that it uses the $source_config instead of $config.

Incidentally, it might be worth also looking at #3004499: Drush feeds-import command ignores stored config for CSV parser as I found other bugs in the importer.

Status: Needs review » Needs work

The last submitted patch, 10: feeds-n1720724-10.patch, failed testing. View results

bluegeek9’s picture

Status: Needs work » Closed (outdated)

Drupal 7 reached end of life and the D7 version of Feeds is no longer being developed. To keep the issue queue focused on supported versions, we’re closing older D7 issues.

If you still have questions about using Feeds on Drupal 7, feel free to ask. While we won’t fix D7 bugs anymore, we’re happy to offer guidance to help you move forward. You can do so by opening (or reopening) a D7 issue, or by reaching out in the #feeds channel on Drupal Slack.

If this issue is still relevant for Drupal 10+, please open a follow-up issue or merge request with proposed changes. Contributions are always welcome!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.