summaryrefslogtreecommitdiff
path: root/ext/spl
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2014-12-06 21:37:15 +0100
committerAnatol Belski <ab@php.net>2014-12-06 21:37:15 +0100
commitba35b22bc4a7af791ff2ab7c2ca8e9f4aa6d64df (patch)
tree92d7a7d9dd424b53e50a194af06ec3cfb514633e /ext/spl
parent88bb9fedc4b5fc750524a7b00be1d46fde2f5929 (diff)
parentaa52fcf179d9e233075e4d213d5708cc5b5e1ae2 (diff)
downloadphp-git-ba35b22bc4a7af791ff2ab7c2ca8e9f4aa6d64df.tar.gz
Merge remote-tracking branch 'origin/master' into native-tls
* origin/master: (35 commits) Fixed bug #68398 msooxml matches too many archives Fix zpp call in apache_getenv() Drop unnecessary zval containers fixed test C89 compat add include for missing localeconv_r proto updated NEWS Fixed bug #65230 setting locale randomly broken Fix compilation error (ref #68424) Removed useless handlers Move checks for references into slow paths of operator functions. Remove duplicate opcode handlers. Revert unintentional docblock change Restored zip/oci8 PHP 4 code, add PHP 7 checks Note macro removal in UPGRADING.INTERNALS Removed ZEND_ENGINE_2 checks (and ZE1 code, it's been a decade!) Zend Engine 3 Updated NEWS Updated NEWS Updated NEWS Start adding new attribute to control multi statements ...
Diffstat (limited to 'ext/spl')
-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 375d52bad9..8da1d1165f 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -2617,20 +2617,27 @@ 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 = Z_SPLFILESYSTEM_P(getThis());
char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape;
- char *delim = NULL, *enclo = NULL;
- size_t d_len = 0, e_len = 0;
+ char *delim = NULL, *enclo = NULL, *esc = NULL;
+ size_t d_len = 0, e_len = 0, esc_len = 0;
zend_long 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");
@@ -3006,6 +3013,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..e4e7976a9b
--- /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===