com php-src: Fixed #68479 - Added escape parameter to SplFileObject::fputcsv: ext/spl/spl_directory.c ext/spl/t ests/SplFileObject_fputcsv_error.phpt
ext/spl/tests/bug 68479.phpt
| From: | JulienPauli | Date: | Fri, 05 Dec 2014 09:10:10 +0000 |
| Subject: | com php-src: Fixed #68479 - Added escape parameter to SplFileObject::fputcsv: ext/spl/spl_directory.c ext/spl/t ests/SplFileObject_fputcsv_error.phpt ext/spl/tests/bug 68479.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-83512@lists.php.net to get a copy of this message | ||
Commit: 557026301f0a49fcc4f358e20e0e126a1eab6fd0
Author: Peter Cowburn <petercowburn@gmail.com> Mon, 24 Nov 2014 20:13:14 +0000
Committer: Julien Pauli <jpauli@php.net> Fri, 5 Dec 2014 10:10:10 +0100
Parents: c65143d571b46d52b82807c0c214c4cc6af9e0fb
Branches: PHP-5.5
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=557026301f0a49fcc4f358e20e0e126a1eab6fd0
Log:
Fixed #68479 - Added escape parameter to SplFileObject::fputcsv
Bugs:
https://bugs.php.net/68479
Changed paths:
M ext/spl/spl_directory.c
M ext/spl/tests/SplFileObject_fputcsv_error.phpt
A ext/spl/tests/bug68479.phpt
Diff:
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 9f4e43f..0d7ef38 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -2615,19 +2615,26 @@ SPL_METHOD(SplFileObject, fgetcsv)
}
/* }}} */
-/* {{{ proto int SplFileObject::fputcsv(array fields, [string delimiter [, string enclosure]])
+/* {{{ proto int SplFileObject::fputcsv(array fields, [string delimiter [, string enclosure [,
string escape]]])
Output a field array as a CSV line */
SPL_METHOD(SplFileObject, fputcsv)
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis()
TSRMLS_CC);
char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape =
intern->u.file.escape;
- char *delim = NULL, *enclo = NULL;
- int d_len = 0, e_len = 0, ret;
+ char *delim = NULL, *enclo = NULL, *esc = NULL;
+ int d_len = 0, e_len = 0, esc_len = 0, ret;
zval *fields = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &fields, &delim,
&d_len, &enclo, &e_len) == SUCCESS) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|sss", &fields, &delim,
&d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
switch(ZEND_NUM_ARGS())
{
+ case 4:
+ if (esc_len != 1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character");
+ RETURN_FALSE;
+ }
+ escape = esc[0];
+ /* no break */
case 3:
if (e_len != 1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
@@ -2945,6 +2952,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fputcsv, 0, 0, 1)
ZEND_ARG_INFO(0, fields)
ZEND_ARG_INFO(0, delimiter)
ZEND_ARG_INFO(0, enclosure)
+ ZEND_ARG_INFO(0, escape)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1)
diff --git a/ext/spl/tests/SplFileObject_fputcsv_error.phpt
b/ext/spl/tests/SplFileObject_fputcsv_error.phpt
index 8368e42..3de88c4 100644
--- a/ext/spl/tests/SplFileObject_fputcsv_error.phpt
+++ b/ext/spl/tests/SplFileObject_fputcsv_error.phpt
@@ -14,7 +14,8 @@ echo "-- Testing fputcsv() with more than expected number of arguments
--\n";
$fields = array("fld1", "fld2");
$delim = ";";
$enclosure ="\"";
-var_dump( $fo->fputcsv($fields, $delim, $enclosure, $fo) );
+$escape = "\\";
+var_dump( $fo->fputcsv($fields, $delim, $enclosure, $escape, $fo) );
echo "Done\n";
--CLEAN--
@@ -30,6 +31,6 @@ Warning: SplFileObject::fputcsv() expects at least 1 parameter, 0 given in %s on
NULL
-- Testing fputcsv() with more than expected number of arguments --
-Warning: SplFileObject::fputcsv() expects at most 3 parameters, 4 given in %s on line %d
+Warning: SplFileObject::fputcsv() expects at most 4 parameters, 5 given in %s on line %d
NULL
Done
diff --git a/ext/spl/tests/bug68479.phpt b/ext/spl/tests/bug68479.phpt
new file mode 100644
index 0000000..1782a9c
--- /dev/null
+++ b/ext/spl/tests/bug68479.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Bug #68479 (Escape parameter missing from SplFileObject::fputcsv)
+--FILE--
+<?php
+
+$method = new ReflectionMethod('SplFileObject', 'fputcsv');
+$params = $method->getParameters();
+var_dump($params);
+
+?>
+===DONE===
+--EXPECTF--
+array(4) {
+ [0]=>
+ &object(ReflectionParameter)#2 (1) {
+ ["name"]=>
+ string(6) "fields"
+ }
+ [1]=>
+ &object(ReflectionParameter)#3 (1) {
+ ["name"]=>
+ string(9) "delimiter"
+ }
+ [2]=>
+ &object(ReflectionParameter)#4 (1) {
+ ["name"]=>
+ string(9) "enclosure"
+ }
+ [3]=>
+ &object(ReflectionParameter)#5 (1) {
+ ["name"]=>
+ string(6) "escape"
+ }
+}
+===DONE===
\ No newline at end of file