Bug #66727 [NEW]: fgetcsv handles default escape character ('\') inconsistently
| From: | ikonta at yandex dot ru | Date: | Mon, 17 Feb 2014 11:48:36 +0000 |
| Subject: | Bug #66727 [NEW]: fgetcsv handles default escape character ('\') inconsistently | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-184336@lists.php.net to get a copy of this message | ||
From: ikonta at yandex dot ru
Operating system: Gentoo GNU/Linux, 17.02.2014
PHP version: 5.5.9
Package: Filesystem function related
Bug Type: Bug
Bug description:fgetcsv handles default escape character ('\') inconsistently
Description:
------------
Issue similiar with bug #66588 but not exact.
Also, #33847 describes almost exact issue. But it doesn't provide a
solution.
Bug #46872 doesn't match actual documentation
http://ru2.php.net/manual/en/function.fgetcsv.php
array fgetcsv ( resource $handle [, int $length = 0 [, string $delimiter
= ',' [, string $enclosure = '"' [, string $escape = '\\' ]]]] )
â¦
escape
Set the escape character (one character only). Defaults as a
backslash.
Last tested on amd64 build of =dev-lang/php-5.5.9:
Installed versions: 5.4.23(5.4)(11:45:23 04.02.2014)(apache2 berkdb
bzip2 calendar cli crypt ctype fileinfo filter gd gdbm hash iconv json
nls oci8-instant-client phar posix readline session simplexml ssl
tokenizer unicode xml xmlreader xmlwriter xpm zip zlib -bcmath -cdb -cgi
-cjk -curl -curlwrappers -debug -embed -enchant -exif -firebird
-flatfile -fpm -frontbase -ftp -gmp -imap -inifile -intl -iodbc -ipv6
-kerberos -ldap -ldap-sasl -libedit -mhash -mssql -mysql -mysqli
-mysqlnd -odbc -pcntl -pdo -postgres -qdbm -recode -selinux -sharedmem
-snmp -soap -sockets -spell -sqlite -sybase-ct -sysvipc -threads -tidy
-truetype -wddx -xmlrpc -xslt) 5.5.9(5.5)(13:59:23 17.02.2014)(apache2
berkdb bzip2 calendar cli crypt ctype fileinfo filter gd gdbm hash iconv
json nls oci8-instant-client opcache phar posix readline session
simplexml ssl tokenizer unicode xml xmlreader xmlwriter xpm zip zlib
-bcmath -cdb -cgi -cjk -curl -debug -embed -enchant -exif -firebird
-flatfile -fpm -frontbase -ftp -gmp -imap -inifile -intl -iodbc -ipv6
-kerberos -ldap -ldap-sasl -libedit -libmysqlclient -mhash -mssql -mysql
-mysqli -odbc -pcntl -pdo -postgres -qdbm -recode -selinux -sharedmem
-snmp -soap -sockets -spell -sqlite -sybase-ct -systemd -sysvipc
-threads -tidy -truetype -wddx -xmlrpc -xslt)
Also planned a check with =dev-lang/php-5.4.25
Test files:
1-st step. Incorrect three filed CSV file:
test.CSV
"05.10.13 12:30:06";"ÑеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока
ÑекÑÑа
\";"12345"
Note: escape special char ('\') in the last data position if middle
(2-nd) field.
2-nd step. Corrected CSV file (with adding missed escape character):
test.CSV
"05.10.13 12:30:06";"ÑеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока
ÑекÑÑа
\\";"12345"
I expect escape special char to be used on parsing string and skipped
without translating to output.
Test script:
---------------
Test script, used to check it is:
<?php
$file_ptr = fopen("/tmp/test.CSV", "r");
while (($record = fgetcsv($file_ptr, 0, ";")) !== FALSE) {
$record_fields = count($record);
echo "Ð ÑÑÑоке ÑазобÑано $record_fields
полей\n";
for ($i = 0; $i < $record_fields; $i++) {
echo $record[$i];
echo "\n";
}
}
?>
Expected result:
----------------
For 1-st file I expect to see warning/error message about
incorrect/incomplete record in file.
With emergency exit or, depending on extra flags, continue parsing file
after skipping bad record.
For 2-n file I expect to see three fields without extra-added escape
char:
05.10.13 12:30:06
ÑеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока ÑекÑÑа \
12345
Actual result:
--------------
1-st file is parsed into two fileds:
05.10.13 12:30:06
ÑеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока ÑекÑÑа
\";12345"
Start double-quote of last field (this time concatenated with 2-nd) is
missed.
Escape special char ('\') is translated to output together with escaped
special char ('"') to output.
2-nd file is parsed into three fileds as expected:
05.10.13 12:30:06
ÑеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока ÑекÑÑа \\
12345
Note: escape special char ('\') is translated to output together with
escaped one.
--
Edit bug report at https://bugs.php.net/bug.php?id=66727&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66727&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66727&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66727&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66727&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66727&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66727&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66727&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66727&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66727&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66727&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66727&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66727&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66727&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66727&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66727&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66727&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66727&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66727&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66727&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66727&r=mysqlcfg