Bug #66727 [Opn]: fgetcsv handles default escape character ('\') inconsistently
| From: | cmb@php.net | Date: | Fri, 26 Aug 2016 13:36:36 +0000 |
| Subject: | Bug #66727 [Opn]: fgetcsv handles default escape character ('\') inconsistently | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203579@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66727&edit=1
ID: 66727
Updated by: cmb@php.net
Reported by: ikonta at yandex dot ru
Summary: fgetcsv handles default escape character ('\')
inconsistently
Status: Open
Type: Bug
Package: Filesystem function related
Operating System: Gentoo GNU/Linux, 17.02.2014
PHP Version: 5.5.9
Block user comment: N
Private report: N
New Comment:
Related to bug #67566.
Previous Comments:
------------------------------------------------------------------------
[2014-02-17 11:48:35] ikonta at yandex dot ru
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 -frontba!
se -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 this bug report at https://bugs.php.net/bug.php?id=66727&edit=1