From: RQuadling at GMail dot com
Operating system: Windows XP SP2
PHP version: 5CVS-2006-08-18 (snap)
PHP Bug Type: Streams related
Bug description: fgetcsv() doesn't report delimiter/enclosure greater than 1
char like fputcsv.
Description:
------------
Hi.
The issue was initially caught when I used '\t' rather than "\t".
The source for fputcsv reports notices when you use a delimiter or an
enclosure of > 1 character. But fgetcsv doesn't report this.
The following patch should fix this.
Index: file.c
===================================================================
RCS file: /repository/php-src/ext/standard/file.c,v
retrieving revision 1.449
diff -u -r1.449 file.c
--- file.c 16 Jul 2006 15:54:25 -0000 1.449
+++ file.c 18 Aug 2006 10:30:51 -0000
@@ -2081,6 +2081,8 @@
if (delimiter_str_len < 1) {
php_error_docref(NULL TSRMLS_CC,
E_WARNING, "delimiter must be a character");
RETURN_FALSE;
+ } else if (delimiter_str_len > 1) {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE,
"delimiter must be a single character");
}
/* use first character from string */
@@ -2091,6 +2093,8 @@
if (enclosure_str_len < 1) {
php_error_docref(NULL TSRMLS_CC,
E_WARNING, "enclosure must be a character");
RETURN_FALSE;
+ } else if (enclosure_str_len > 1) {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE,
"enclosure must be a single character");
}
/* use first character from string */
enclosure = enclosure_str[0];
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
++$dummy; // Proof of notices working.
// Store CSV like data in temporary file.
$fp = tmpfile();
// Real data I've been given - yeuch!
fwrite($fp, <<< END_DATA
BO1`11519`112733`CELTIC002`2002/01/02````D.W.`Marilyn````````2`2``2`1225`10039
BO1`11520`=VARIOUS`HILL
1`2002/01/18````Various`Marilyn````````36``36`36`1225`VARIOUS
BO1`11521`+VARIOUS`HILL
1`2002/01/14````Various`Marilyn````````32``32`32`1225`VARIOUS
BO1`11522`\\VARIOUS`HILL
1`2002/01/14````Various`Marilyn````````133``133`133`1225`VARIOUS
BO1`11523`113027`FRAIKIN006`2002/01/02````S.W.`Marilyn```````10`1``1`1`1225`AAN124
END_DATA
);
// Reset the file pointer.
fseek($fp, 0, SEEK_SET);
// Get data and report the number of
$a = array
(
fgetcsv($fp, 8192, '``'), // Expect notice - php_error_docref(NULL
TSRMLS_CC, E_NOTICE, "delimiter must be a single character")
fgetcsv($fp, 8192, '`', '\t'), // Expect notice - php_error_docref(NULL
TSRMLS_CC, E_NOTICE, "enclosure must be a single character");
fgetcsv($fp, 8192, '`', '\t'), // Expect notice - php_error_docref(NULL
TSRMLS_CC, E_NOTICE, "enclosure must be a single character");
fgetcsv($fp, 8192, '`', '\t'), // Expect notice - php_error_docref(NULL
TSRMLS_CC, E_NOTICE, "enclosure must be a single character");
fgetcsv($fp, 8192, '`', "\t"), // Nothing wrong with this one.
);
foreach($a as $b)
{
// Each row has 23 values.
echo count($b), ' ', $b[2], "\n";
}
fclose($fp);
?>
Expected result:
----------------
Notices about enclosure or delimiter not being a single character like
fputcsv
Actual result:
--------------
Notice: Undefined variable: dummy in C:\a.php on line 3
23 112733
23 =VARIOUS
23 +VARIOUS
3 VARIOUS`HILL
1`2002/01/14````Various`Marilyn````````133``133`133`1225`VARIOUS
BO1`11523`113027`FRAIKIN006`2002/01/02````S.W.`Marilyn```````10`1``1`1`1225`AAN124
1
--
Edit bug report at http://bugs.php.net/?id=38496&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=38496&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=38496&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=38496&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38496&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=38496&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38496&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38496&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38496&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38496&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38496&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=38496&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=38496&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38496&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38496&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38496&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38496&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38496&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38496&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38496&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38496&r=mysqlcfg