Skip to content

Commit b1bf524

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Revert "Update fputcsv() to escape all characters equally."
2 parents 374ebc8 + c077074 commit b1bf524

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

NEWS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ PHP NEWS
99
(Laruence)
1010
. Fixed bug #63899 (Use after scope error in zend_compile). (Laruence)
1111
. Fixed bug #63882 (zend_std_compare_objects crash on recursion). (Dmitry)
12-
. Fixed bug #43225 (fputcsv incorrectly handles cells ending in \ followed
13-
by "). (Adam)
1412
. Support BITMAPV5HEADER in getimagesize(). (AsamK, Lars)
1513

1614
- Date:

ext/standard/file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,16 +1871,20 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en
18711871
FPUTCSV_FLD_CHK('\n') ||
18721872
FPUTCSV_FLD_CHK('\r') ||
18731873
FPUTCSV_FLD_CHK('\t') ||
1874-
FPUTCSV_FLD_CHK('\\') ||
18751874
FPUTCSV_FLD_CHK(' ')
18761875
) {
18771876
char *ch = Z_STRVAL(field);
18781877
char *end = ch + Z_STRLEN(field);
1878+
int escaped = 0;
18791879

18801880
smart_str_appendc(&csvline, enclosure);
18811881
while (ch < end) {
1882-
if (*ch == enclosure) {
1882+
if (*ch == escape_char) {
1883+
escaped = 1;
1884+
} else if (!escaped && *ch == enclosure) {
18831885
smart_str_appendc(&csvline, enclosure);
1886+
} else {
1887+
escaped = 0;
18841888
}
18851889
smart_str_appendc(&csvline, *ch);
18861890
ch++;

ext/standard/tests/file/fputcsv.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ echo '$list = ';var_export($res);echo ";\n";
4444

4545
$fp = fopen($file, "r");
4646
$res = array();
47-
while($l=fgetcsv($fp, 0, ',', '"', '"'))
47+
while($l=fgetcsv($fp))
4848
{
4949
$res[] = join(',',$l);
5050
}
@@ -75,10 +75,10 @@ $list = array (
7575
13 => 'aaa,"""bbb """',
7676
14 => '"aaa""aaa""","""bbb""bbb"',
7777
15 => '"aaa""aaa""""""",bbb',
78-
16 => 'aaa,"""\\""bbb",ccc',
79-
17 => '"aaa""\\""a""","""bbb"""',
80-
18 => '"""\\""""","""aaa"""',
81-
19 => '"""\\""""""",aaa',
78+
16 => 'aaa,"""\\"bbb",ccc',
79+
17 => '"aaa""\\"a""","""bbb"""',
80+
18 => '"""\\"""","""aaa"""',
81+
19 => '"""\\"""""",aaa',
8282
);
8383
$list = array (
8484
0 => 'aaa,bbb',

ext/standard/tests/file/fputcsv_bug43225.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)