1
0
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:
Juan Morales
2024-04-06 19:18:12 -03:00
committed by GitHub
parent 9a4847acf5
commit c96b975f67
2 changed files with 18 additions and 18 deletions

View File

@@ -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);

View 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