diff options
author | Adam Harvey <aharvey@php.net> | 2013-01-15 15:24:21 +0800 |
---|---|---|
committer | Adam Harvey <aharvey@php.net> | 2013-01-15 15:24:21 +0800 |
commit | a4191b0aad94fb7bebb8fd5c4233006849845c31 (patch) | |
tree | d6465eda449ec72057aba09263df14e5c6536be5 | |
parent | 6a065876b9212404daaf8fee1708834da83dac56 (diff) | |
parent | 9b5cb0e8059b1e8bec096067491ed8d75f878938 (diff) | |
download | php-git-a4191b0aad94fb7bebb8fd5c4233006849845c31.tar.gz |
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3:
Update fputcsv() to escape all characters equally.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/standard/file.c | 8 | ||||
-rw-r--r-- | ext/standard/tests/file/fputcsv.phpt | 10 | ||||
-rw-r--r-- | ext/standard/tests/file/fputcsv_bug43225.phpt | 20 |
4 files changed, 29 insertions, 11 deletions
@@ -8,6 +8,8 @@ PHP NEWS . Fixed bug #63943 (Bad warning text from strpos() on empty needle). (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) - Litespeed: diff --git a/ext/standard/file.c b/ext/standard/file.c index f7af63bcf4..b2d44f113b 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1871,20 +1871,16 @@ 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 == escape_char) { - escaped = 1; - } else if (!escaped && *ch == enclosure) { + if (*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 63c41509bd..d71f777143 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)) +while($l=fgetcsv($fp, 0, ',', '"', '"')) { $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 new file mode 100644 index 0000000000..1de3b5fa02 --- /dev/null +++ b/ext/standard/tests/file/fputcsv_bug43225.phpt @@ -0,0 +1,20 @@ +--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 |