[PHP-CVS] com php-src: Revert Update fputcsv() to escape all characters equally.: ext/standard/file.c ext/standard/tests/file/fputcsv.phpt ext/standard/tests/file/fputcsv_bug43225.phpt
Commit:232cf4a640f00932e8030b0d57541a8d5c286309 Author:Adam Harvey ahar...@php.net Tue, 15 Jan 2013 17:33:54 +0800 Parents: c77fe090ea8dcbf0ceab924c748182ea472ef32d Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=232cf4a640f00932e8030b0d57541a8d5c286309 Log: Revert Update fputcsv() to escape all characters equally. On second thoughts, while the behaviour _is_ broken, this isn't the right fix. This reverts commit 9b5cb0e8059b1e8bec096067491ed8d75f878938. Changed paths: M ext/standard/file.c M ext/standard/tests/file/fputcsv.phpt D ext/standard/tests/file/fputcsv_bug43225.phpt Diff: diff --git a/ext/standard/file.c b/ext/standard/file.c index 574fb53..74577ac 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 d71f777..63c4150 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 = 'aa,bb', 15 = 'aa,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 1de3b5f..000 --- 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 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] com php-src: Revert Update fputcsv() to escape all characters equally.: ext/standard/file.c ext/standard/tests/file/fputcsv.phpt ext/standard/tests/file/fputcsv_bug43225.phpt
Commit:cab290d2adbd616a18b9efaace6abe629f827190 Author:Adam Harvey ahar...@php.net Tue, 15 Jan 2013 17:33:54 +0800 Parents: dc495bbe95680a9cf2321da83a382d834d70758c Branches: PHP-5.5 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cab290d2adbd616a18b9efaace6abe629f827190 Log: Revert Update fputcsv() to escape all characters equally. On second thoughts, while the behaviour _is_ broken, this isn't the right fix. This reverts commit 9b5cb0e8059b1e8bec096067491ed8d75f878938. Changed paths: M ext/standard/file.c M ext/standard/tests/file/fputcsv.phpt D ext/standard/tests/file/fputcsv_bug43225.phpt Diff: diff --git a/ext/standard/file.c b/ext/standard/file.c index 574fb53..74577ac 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 d71f777..63c4150 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 = 'aa,bb', 15 = 'aa,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 1de3b5f..000 --- 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 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php