Bug #55763 [NEW]: str_getcsv incorrectly handles line-breaks inside fields
| From: | talk at alexmingoia dot com | Date: | Thu, 22 Sep 2011 16:41:15 +0000 |
| Subject: | Bug #55763 [NEW]: str_getcsv incorrectly handles line-breaks inside fields | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-163790@lists.php.net to get a copy of this message | ||
From:
Operating system: OS X 10.6
PHP version: 5.3.8
Package: Strings related
Bug Type: Bug
Bug description:str_getcsv incorrectly handles line-breaks inside fields
Description:
------------
RFC4180 states that fields can contain line breaks as long as they are
properly enclosed by double-quotes.
str_getcsv treats line-breaks inside of enclosed fields as new records in
the CSV.
Setting 'auto_detect_line_ending' to TRUE or using "\r\n" instead of
"\n"
still produces incorrect results.
Test script:
---------------
$csv = file_get_contents('test.csv');
$csvArray = str_getcsv($csv, "\n");
var_dump($csvArray);
Expected result:
----------------
array(4) {
[0]=>
string(15) "Name,Desc,Email"
[1]=>
string(4) "Alex"
[2]=>
string(18) "Is a PHP developer"
[3]=>
string(16) "alex@example.com"
}
Actual result:
--------------
array(4) {
[0]=>
string(15) "Name,Desc,Email"
[1]=>
string(14) "Alex,"Is a PHP"
[2]=>
string(9) "developer"
[3]=>
string(17) ",alex@example.com"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=55763&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55763&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55763&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55763&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=55763&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55763&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=55763&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=55763&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=55763&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=55763&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=55763&r=support
Expected behavior: https://bugs.php.net/fix.php?id=55763&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=55763&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=55763&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=55763&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55763&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=55763&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=55763&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=55763&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=55763&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=55763&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=55763&r=mysqlcfg