From f15f8c6a191d39f821f00b0a78b895f418b01d23 Mon Sep 17 00:00:00 2001 From: juan-morales Date: Mon, 25 Mar 2024 16:37:17 -0300 Subject: [PATCH 1/2] filter_input_array - returns only NULL if input is not present --- ext/filter/filter.c | 20 ++------------------ ext/filter/tests/filter_input_array_001.phpt | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 ext/filter/tests/filter_input_array_001.phpt diff --git a/ext/filter/filter.c b/ext/filter/filter.c index b787ef706c4f2..ee8db5ef3583b 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -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); diff --git a/ext/filter/tests/filter_input_array_001.phpt b/ext/filter/tests/filter_input_array_001.phpt new file mode 100644 index 0000000000000..0b6f213165b86 --- /dev/null +++ b/ext/filter/tests/filter_input_array_001.phpt @@ -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-- + [ + "flags" => FILTER_NULL_ON_FAILURE, + ] + ]; + + var_dump(filter_input_array(INPUT_GET, $args, true)); +?> +--EXPECT-- +NULL From 0679b569846d27dab0f33009876ef30faa30523b Mon Sep 17 00:00:00 2001 From: juan-morales Date: Mon, 25 Mar 2024 18:05:32 -0300 Subject: [PATCH 2/2] remove indentation --- ext/filter/tests/filter_input_array_001.phpt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/filter/tests/filter_input_array_001.phpt b/ext/filter/tests/filter_input_array_001.phpt index 0b6f213165b86..038ebc6dd2cdf 100644 --- a/ext/filter/tests/filter_input_array_001.phpt +++ b/ext/filter/tests/filter_input_array_001.phpt @@ -4,13 +4,13 @@ filter_input_array: test FILTER_NULL_ON_FAILURE option does not affect general r filter --FILE-- [ - "flags" => FILTER_NULL_ON_FAILURE, - ] - ]; +$args = [ + "c" => [ + "flags" => FILTER_NULL_ON_FAILURE, + ] +]; - var_dump(filter_input_array(INPUT_GET, $args, true)); +var_dump(filter_input_array(INPUT_GET, $args, true)); ?> --EXPECT-- NULL