summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harvey <aharvey@php.net>2013-01-15 17:35:34 +0800
committerAdam Harvey <aharvey@php.net>2013-01-15 17:35:34 +0800
commitb1bf524140f3825d161c6e8f922b696d91b93969 (patch)
tree5ed72700e5cd022f25216054842b11437ab49edc
parent374ebc87416d9e31efd961a3176510e3a901355b (diff)
parentc077074c1379b5faed386106fdbb53f5d17fd6e7 (diff)
downloadphp-git-b1bf524140f3825d161c6e8f922b696d91b93969.tar.gz
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Revert "Update fputcsv() to escape all characters equally."
-rw-r--r--NEWS2
-rw-r--r--ext/standard/file.c8
-rw-r--r--ext/standard/tests/file/fputcsv.phpt10
-rw-r--r--ext/standard/tests/file/fputcsv_bug43225.phpt20
4 files changed, 11 insertions, 29 deletions
diff --git a/NEWS b/NEWS
index 5f45667576..8201ce1b4c 100644
--- a/NEWS
+++ b/NEWS
@@ -9,8 +9,6 @@ PHP NEWS
(Laruence)
. Fixed bug #63899 (Use after scope error in zend_compile). (Laruence)
. Fixed bug #63882 (zend_std_compare_objects crash on recursion). (Dmitry)
- . Fixed bug #43225 (fputcsv incorrectly handles cells ending in \ followed
- by "). (Adam)
. Support BITMAPV5HEADER in getimagesize(). (AsamK, Lars)
- Date:
diff --git a/ext/standard/file.c b/ext/standard/file.c
index b2d44f113b..f7af63bcf4 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -1871,16 +1871,20 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en
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++;
diff --git a/ext/standard/tests/file/fputcsv.phpt b/ext/standard/tests/file/fputcsv.phpt
index d71f777143..63c41509bd 100644
--- a/ext/standard/tests/file/fputcsv.phpt
+++ b/ext/standard/tests/file/fputcsv.phpt
@@ -44,7 +44,7 @@ echo '$list = ';var_export($res);echo ";\n";
$fp = fopen($file, "r");
$res = array();
-while($l=fgetcsv($fp, 0, ',', '"', '"'))
+while($l=fgetcsv($fp))
{
$res[] = join(',',$l);
}
@@ -75,10 +75,10 @@ $list = array (
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',
diff --git a/ext/standard/tests/file/fputcsv_bug43225.phpt b/ext/standard/tests/file/fputcsv_bug43225.phpt
deleted file mode 100644
index 1de3b5fa02..0000000000
--- a/ext/standard/tests/file/fputcsv_bug43225.phpt
+++ /dev/null
@@ -1,20 +0,0 @@
---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