[PR][php-src][#1148][PHP-5.5] - Fixes bug #69181 (csv parsing drops newlines within fields with SplFileObject::DROP_NEW_LINE)
| From: | noreply@php.net | Date: | Thu, 05 Mar 2015 12:19:34 +0000 |
| Subject: | [PR][php-src][#1148][PHP-5.5] - Fixes bug #69181 (csv parsing drops newlines within fields with SplFileObject::DROP_NEW_LINE) | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-2582@lists.php.net to get a copy of this message | ||
You can view the Pull Request on github:
https://github.com/php/php-src/pull/1148
Pull Request Description:
This pull request fixes buggy behaviour when using
SplFileObject to work with CSV
files.
According to the documentation, the DROP_NEW_LINE flag drops newlines at the end of a
line. http://php.net/manual/en/class.splfileobject.php#splfileobject.constants.drop-new-line
However, even though CSV files are obviously stored with new lines at the end of each line, the
_fields within the CSV can also contain any number of newline characters, as long as they are
quoted_. In this case, the bug appears, as the DROP_NEW_LINE flag causes c function
strcspn to remove the first, and only the first, newline from the entire row of fields.
My solution is to ignore the strcspn function when parsing CSV files, because if there
_are_ any newlines within fields, the fields MUST be delimited, therefore no newlines should be
dropped within the delimiters.