summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/spl/spl_directory.c16
-rw-r--r--ext/spl/tests/SplFileObject_fputcsv_error.phpt5
-rw-r--r--ext/spl/tests/bug68479.phpt35
3 files changed, 50 insertions, 6 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 4437ca8749..8e04de7ce9 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -2643,19 +2643,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");
@@ -3030,6 +3037,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 cdee48c874..4763455907 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 0000000000..1782a9cef2
--- /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