- Core
. Fixed bug #63943 (Bad warning text from strpos() on empty needle).
(Laruence)
- . Fixed bug #43225 (fputcsv incorrectly handles cells ending in \ followed
- by "). (Adam)
- cURL extension:
. Fixed bug (segfault due to libcurl connection caching). (Pierrick)
{
char delimiter = ','; /* allow this to be set as parameter */
char enclosure = '"'; /* allow this to be set as parameter */
+ const char escape_char = '\\';
php_stream *stream;
int ret;
zval *fp = NULL, *fields = NULL, **field_tmp = NULL, field;
/* enclose a field that contains a delimiter, an enclosure character, or a newline */
if (FPUTCSV_FLD_CHK(delimiter) ||
FPUTCSV_FLD_CHK(enclosure) ||
+ FPUTCSV_FLD_CHK(escape_char) ||
FPUTCSV_FLD_CHK('\n') ||
FPUTCSV_FLD_CHK('\r') ||
FPUTCSV_FLD_CHK('\t') ||
- FPUTCSV_FLD_CHK('\\') ||
FPUTCSV_FLD_CHK(' ')
) {
char *ch = Z_STRVAL(field);
char *end = ch + Z_STRLEN(field);
+ int escaped = 0;
smart_str_appendc(&csvline, enclosure);
while (ch < end) {
- if (*ch == enclosure) {
+ if (*ch == escape_char) {
+ escaped = 1;
+ } else if (!escaped && *ch == enclosure) {
smart_str_appendc(&csvline, enclosure);
+ } else {
+ escaped = 0;
}
smart_str_appendc(&csvline, *ch);
ch++;
$fp = fopen($file, "r");
$res = array();
-while($l=fgetcsv($fp, 0, ',', '"', '"'))
+while($l=fgetcsv($fp))
{
$res[] = join(',',$l);
}
13 => 'aaa,"""bbb """',
14 => '"aaa""aaa""","""bbb""bbb"',
15 => '"aaa""aaa""""""",bbb',
- 16 => 'aaa,"""\\""bbb",ccc',
- 17 => '"aaa""\\""a""","""bbb"""',
- 18 => '"""\\""""","""aaa"""',
- 19 => '"""\\""""""",aaa',
+ 16 => 'aaa,"""\\"bbb",ccc',
+ 17 => '"aaa""\\"a""","""bbb"""',
+ 18 => '"""\\"""","""aaa"""',
+ 19 => '"""\\"""""",aaa',
);
$list = array (
0 => 'aaa,bbb',
+++ /dev/null
---TEST--
-fputcsv(): bug #43225 (fputcsv incorrectly handles cells ending in \ followed by ")
---FILE--
-<?php
-
-$row = array(
- 'a\\"',
- 'bbb',
-);
-
-$file = dirname(__FILE__) . 'fgetcsv_bug43225.csv';
-$fp = fopen($file, 'w');
-fputcsv($fp, $row);
-fclose($fp);
-readfile($file);
-unlink($file);
-
-?>
---EXPECT--
-"a\""",bbb