mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
filter_input_array - Implement solution 2 of GH-13805 (#13804)
This commit is contained in:
@@ -690,29 +690,13 @@ PHP_FUNCTION(filter_input_array)
|
||||
}
|
||||
|
||||
array_input = php_filter_get_storage(fetch_from);
|
||||
|
||||
if (EG(exception)) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if (!array_input) {
|
||||
zend_long filter_flags = 0;
|
||||
zval *option;
|
||||
if (op_long) {
|
||||
filter_flags = op_long;
|
||||
} else if (op_ht && (option = zend_hash_str_find(op_ht, "flags", sizeof("flags") - 1)) != NULL) {
|
||||
filter_flags = zval_get_long(option);
|
||||
}
|
||||
|
||||
/* The FILTER_NULL_ON_FAILURE flag inverts the usual return values of
|
||||
* the function: normally when validation fails false is returned, and
|
||||
* when the input value doesn't exist NULL is returned. With the flag
|
||||
* set, NULL and false should be returned, respectively. Ergo, although
|
||||
* the code below looks incorrect, it's actually right. */
|
||||
if (filter_flags & FILTER_NULL_ON_FAILURE) {
|
||||
RETURN_FALSE;
|
||||
} else {
|
||||
RETURN_NULL();
|
||||
}
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
php_filter_array_handler(array_input, op_ht, op_long, return_value, add_empty);
|
||||
|
||||
16
ext/filter/tests/filter_input_array_001.phpt
Normal file
16
ext/filter/tests/filter_input_array_001.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
filter_input_array: test FILTER_NULL_ON_FAILURE option does not affect general result on empty input
|
||||
--EXTENSIONS--
|
||||
filter
|
||||
--FILE--
|
||||
<?php
|
||||
$args = [
|
||||
"c" => [
|
||||
"flags" => FILTER_NULL_ON_FAILURE,
|
||||
]
|
||||
];
|
||||
|
||||
var_dump(filter_input_array(INPUT_GET, $args, true));
|
||||
?>
|
||||
--EXPECT--
|
||||
NULL
|
||||
Reference in New Issue
Block a user